Class: RSpec::Rails::Api::EntityConfig
- Inherits:
-
Object
- Object
- RSpec::Rails::Api::EntityConfig
- Defined in:
- lib/rspec/rails/api/entity_config.rb
Overview
Represents an entity configuration. Basically, entities configuration only have a collection of fields and a method to serialize them for comparison with actual content
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
Instance Method Summary collapse
-
#expand_with(entities) ⇒ Hash
Replaces the arrays ‘of’ and objects ‘attributes’ with the corresponding entities, recursively.
-
#initialize(fields) ⇒ EntityConfig
constructor
A new instance of EntityConfig.
-
#to_h ⇒ Hash
Entity configuration.
Constructor Details
#initialize(fields) ⇒ EntityConfig
14 15 16 17 18 19 |
# File 'lib/rspec/rails/api/entity_config.rb', line 14 def initialize(fields) @fields = {} fields.each_pair do |name, definition| @fields[name] = FieldConfig.new(**definition) end end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
12 13 14 |
# File 'lib/rspec/rails/api/entity_config.rb', line 12 def fields @fields end |
Instance Method Details
#expand_with(entities) ⇒ Hash
Replaces the arrays ‘of’ and objects ‘attributes’ with the corresponding entities, recursively
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rspec/rails/api/entity_config.rb', line 38 def (entities) hash = to_h hash.each_pair do |field, config| next unless i[array object].include? config[:type] attribute = config[:attributes] hash[field][:attributes] = if attribute.is_a? Symbol attribute, entities elsif @fields[field].attributes @fields[field].attributes. entities end end end |
#to_h ⇒ Hash
23 24 25 26 27 28 29 |
# File 'lib/rspec/rails/api/entity_config.rb', line 23 def to_h out = {} @fields.each_key do |key| out[key] = @fields[key].to_h end out end |