Class: ApiBlueprint::Builder

Inherits:
Struct
  • Object
show all
Defined in:
lib/api-blueprint/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

new

Instance Attribute Details

#body=(value) ⇒ Object (writeonly)

Sets the attribute body

Parameters:

  • value

    the value to set the attribute body to.



10
11
12
# File 'lib/api-blueprint/builder.rb', line 10

def body=(value)
  @body = value
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
# File 'lib/api-blueprint/builder.rb', line 12

def build
  if body.is_a? Array
    body.collect { |item| build_item prepare_item(item) }
  else
    build_item prepare_item(body)
  end
end

#build_item(item) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/api-blueprint/builder.rb', line 29

def build_item(item)
  if creates.present?
    creates.new item
  else
    raise BuilderError, "To build an object, you must set #creates"
  end
end

#prepare_item(item) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/api-blueprint/builder.rb', line 20

def prepare_item(item)
  meta = {
    response_headers: headers,
    response_status: status
  }

  meta.merge KeyReplacer.replace(item.deep_symbolize_keys, replacements)
end