class RSpec::Rails::Api::FieldConfig
Represents an entity field configuration. A field have some options and a method to serialize itself.
Attributes
attributes[RW]
description[RW]
required[RW]
type[RW]
Public Class Methods
new(type:, description:, required: true, attributes: nil, of: nil)
click to toggle source
# File lib/rspec/rails/api/field_config.rb, line 14 def initialize(type:, description:, required: true, attributes: nil, of: nil) @required = required @description = description raise "Field type not allowed: '#{type}'" unless Utils.check_attribute_type(type) define_attributes attributes if type == :object define_attributes of if type == :array @type = type end
Public Instance Methods
to_h()
click to toggle source
# File lib/rspec/rails/api/field_config.rb, line 25 def to_h out = { required: @required, type: @type } out[:description] = @description unless @description.nil? if %i[object array].include?(@type) && @attributes out[:attributes] = if @attributes.is_a? EntityConfig @attributes.to_h elsif attributes.is_a? Symbol @attributes end end out end
Private Instance Methods
define_attributes(attributes)
click to toggle source
# File lib/rspec/rails/api/field_config.rb, line 42 def define_attributes(attributes) @attributes = case attributes when Hash @attributes = EntityConfig.new attributes when Symbol attributes end end