Class: Belt::ResponseModelBuilder
- Inherits:
-
Object
- Object
- Belt::ResponseModelBuilder
- Defined in:
- lib/belt/route_dsl.rb
Constant Summary collapse
- SUPPORTED_TYPES =
%i[string text number integer boolean date datetime array object map list].freeze
Instance Attribute Summary collapse
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #context(name) ⇒ Object
-
#initialize(name) ⇒ ResponseModelBuilder
constructor
A new instance of ResponseModelBuilder.
- #to_h ⇒ Object
Constructor Details
#initialize(name) ⇒ ResponseModelBuilder
Returns a new instance of ResponseModelBuilder.
606 607 608 609 610 |
# File 'lib/belt/route_dsl.rb', line 606 def initialize(name) @name = name @contexts = {} @fields = [] end |
Instance Attribute Details
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
604 605 606 |
# File 'lib/belt/route_dsl.rb', line 604 def contexts @contexts end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
604 605 606 |
# File 'lib/belt/route_dsl.rb', line 604 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
604 605 606 |
# File 'lib/belt/route_dsl.rb', line 604 def name @name end |
Instance Method Details
#context(name) ⇒ Object
618 619 620 621 622 |
# File 'lib/belt/route_dsl.rb', line 618 def context(name, &) builder = ContextBuilder.new(name) builder.instance_eval(&) if block_given? @contexts[name] = builder end |
#to_h ⇒ Object
624 625 626 627 628 |
# File 'lib/belt/route_dsl.rb', line 624 def to_h result = { name: @name.to_s, contexts: @contexts.transform_values(&:to_h) } result[:properties] = fields_to_properties unless @fields.empty? result end |