Class: SchemaMatcher::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_matcher/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ Entity

Returns a new instance of Entity.



5
6
7
8
# File 'lib/schema_matcher/entity.rb', line 5

def initialize(&blk)
  @attributes = {}
  instance_exec(&blk)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/schema_matcher/entity.rb', line 3

def attributes
  @attributes
end

Instance Method Details

#attribute(name, options = {}, &blk) ⇒ Object



10
11
12
13
14
# File 'lib/schema_matcher/entity.rb', line 10

def attribute(name, options = {}, &blk)
  return attributes[name] = { type: self.class.new(&blk) }.merge(options).compact if block_given?

  attributes[name] = { type: :string }.merge(options).compact
end

#to_schemaObject



16
17
18
19
20
21
# File 'lib/schema_matcher/entity.rb', line 16

def to_schema
  {
    type: :object,
    properties: attributes.transform_values { |attribute| swaggerize_attribute(attribute) }.compact
  }
end