Class: RSpec::Rails::Api::FieldConfig
- Inherits:
-
Object
- Object
- RSpec::Rails::Api::FieldConfig
- Defined in:
- lib/rspec/rails/api/field_config.rb
Overview
Represents an entity field configuration. A field have some options and a method to serialize itself.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#description ⇒ Object
Returns the value of attribute description.
-
#required ⇒ Object
Returns the value of attribute required.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type:, required: true, description:, attributes: nil, of: nil) ⇒ FieldConfig
constructor
A new instance of FieldConfig.
- #to_h ⇒ Object
Constructor Details
#initialize(type:, required: true, description:, attributes: nil, of: nil) ⇒ FieldConfig
Returns a new instance of FieldConfig.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rspec/rails/api/field_config.rb', line 14 def initialize(type:, required: true, description:, 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 |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
12 13 14 |
# File 'lib/rspec/rails/api/field_config.rb', line 12 def attributes @attributes end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/rspec/rails/api/field_config.rb', line 12 def description @description end |
#required ⇒ Object
Returns the value of attribute required.
12 13 14 |
# File 'lib/rspec/rails/api/field_config.rb', line 12 def required @required end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/rspec/rails/api/field_config.rb', line 12 def type @type end |
Instance Method Details
#to_h ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |