Class: ApiSketch::DSL::Attributes

Inherits:
Base
  • Object
show all
Defined in:
lib/api_sketch/dsl/attributes.rb

Constant Summary collapse

TYPES =
[:integer, :string, :float, :boolean, :datetime, :timestamp, :document, :array, :file]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#use_shared_block

Constructor Details

#initialize(container_type, &block) ⇒ Attributes

Returns a new instance of Attributes.



5
6
7
8
9
10
# File 'lib/api_sketch/dsl/attributes.rb', line 5

def initialize(container_type, &block)
  @container_type = container_type
  @params = []
  define_singleton_method(:initialize_attributes, block)
  initialize_attributes
end

Class Method Details

.build_by(data_type, attribute_name, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/api_sketch/dsl/attributes.rb', line 33

def build_by(data_type, attribute_name, &block)
  options = {data_type: data_type}
  options[:name] = attribute_name if attribute_name
  case data_type
  when :document, :array
    ::ApiSketch::Model::Attribute.new(::ApiSketch::DSL::ComplexAttributeParser.new(data_type, &block).to_h.merge(options))
  else
    ::ApiSketch::Model::Attribute.new(::ApiSketch::DSL::AttributeParser.new(data_type, &block).to_h.merge(options))
  end
end

Instance Method Details

#to_aObject



12
13
14
# File 'lib/api_sketch/dsl/attributes.rb', line 12

def to_a
  @params
end