Class: Belt::ResponseModelBuilder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ResponseModelBuilder

Returns a new instance of ResponseModelBuilder.



734
735
736
737
738
# File 'lib/belt/route_dsl.rb', line 734

def initialize(name)
  @name = name
  @contexts = {}
  @fields = []
end

Instance Attribute Details

#contextsObject (readonly)

Returns the value of attribute contexts.



732
733
734
# File 'lib/belt/route_dsl.rb', line 732

def contexts
  @contexts
end

#fieldsObject (readonly)

Returns the value of attribute fields.



732
733
734
# File 'lib/belt/route_dsl.rb', line 732

def fields
  @fields
end

#nameObject (readonly)

Returns the value of attribute name.



732
733
734
# File 'lib/belt/route_dsl.rb', line 732

def name
  @name
end

Instance Method Details

#context(name) ⇒ Object



746
747
748
749
750
# File 'lib/belt/route_dsl.rb', line 746

def context(name, &)
  builder = ContextBuilder.new(name)
  builder.instance_eval(&) if block_given?
  @contexts[name] = builder
end

#to_hObject



752
753
754
755
756
# File 'lib/belt/route_dsl.rb', line 752

def to_h
  result = { name: @name.to_s, contexts: @contexts.transform_values(&:to_h) }
  result[:properties] = fields_to_properties unless @fields.empty?
  result
end