Class: RSpec::Rails::Api::EntityConfig

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ EntityConfig

Returns a new instance of EntityConfig.



14
15
16
17
18
19
# File 'lib/rspec/rails/api/entity_config.rb', line 14

def initialize(fields)
  @fields = {}
  fields.each_key do |name|
    @fields[name] = FieldConfig.new fields[name]
  end
end

Instance Attribute Details

#fieldsObject

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) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rspec/rails/api/entity_config.rb', line 29

def expand_with(entities)
  hash = to_h
  hash.each_pair do |field, config|
    next unless %i[array object].include? config[:type]

    attributes = config[:attributes]
    next unless attributes.is_a? Symbol
    raise "Entity #{attributes} not found for entity completion." unless entities[attributes]

    hash[field][:attributes] = entities[attributes].expand_with(entities)
  end
end

#to_hObject



21
22
23
24
25
26
27
# File 'lib/rspec/rails/api/entity_config.rb', line 21

def to_h
  out = {}
  @fields.each_key do |key|
    out[key] = @fields[key].to_h
  end
  out
end