Class: Paradocs::Extensions::PayloadBuilder
- Defined in:
- lib/paradocs/extensions/payload_builder.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#skip_word ⇒ Object
Returns the value of attribute skip_word.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
Instance Method Summary collapse
- #build!(sort_by_schema: false, &block) ⇒ Object
-
#initialize(schema, skip_word: :skip) ⇒ PayloadBuilder
constructor
A new instance of PayloadBuilder.
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
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/paradocs/extensions/payload_builder.rb', line 4 def result @result end |
#skip_word ⇒ Object
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 |
#structure ⇒ Object (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 |