Class: Simplifyapi::Builder

Inherits:
Object
  • Object
show all
Includes:
DSLMethods
Defined in:
lib/simplifyapi/builder.rb

Instance Method Summary collapse

Methods included from DSLMethods

#collection, #initialize, #method_missing, #property

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Simplifyapi::DSLMethods

Instance Method Details

#export(representer, model) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simplifyapi/builder.rb', line 5

def export representer, model
  @store = {}
  @representer = representer
  @model = model

  # Registering keys and properties
  @block.call(self, @model) if @block

  hash = {}

  # Then we play the score accordingly
  @store.each do |key, object|
    if object.is_a? Builder
      hash[key] = object.export(representer, model)
    else
      if object.respond_to? :export
        hash[key] = object.export(@model)
      else
        hash[key] = object
      end
    end
  end

  hash
end