Class: Paradocs::Extensions::PayloadBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/paradocs/extensions/payload_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, skip_word: :skip) ⇒ PayloadBuilder

Returns a new instance of PayloadBuilder.



6
7
8
9
# File 'lib/paradocs/extensions/payload_builder.rb', line 6

def initialize(schema, skip_word: :skip)
  @structure  = schema.structure
  @skip_word  = skip_word
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/paradocs/extensions/payload_builder.rb', line 4

def result
  @result
end

#skip_wordObject

Returns the value of attribute skip_word.



5
6
7
# File 'lib/paradocs/extensions/payload_builder.rb', line 5

def skip_word
  @skip_word
end

#structureObject (readonly)

Returns the value of attribute structure.



4
5
6
# File 'lib/paradocs/extensions/payload_builder.rb', line 4

def structure
  @structure
end

Instance Method Details

#build!(sort_by_schema: false, &block) ⇒ Object



11
12
13
14
# File 'lib/paradocs/extensions/payload_builder.rb', line 11

def build!(sort_by_schema: false, &block)
  result = structure.all_nested.map { |name, struct| [name, build_simple_structure(struct, &block)] }.to_h
  sort_by_schema ? schema.resolve(result).output : result
end