Class: SchemaMatcher::Entity
- Inherits:
-
Object
- Object
- SchemaMatcher::Entity
- Defined in:
- lib/schema_matcher/entity.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #attribute(name, options = {}, &blk) ⇒ Object
-
#initialize(&blk) ⇒ Entity
constructor
A new instance of Entity.
- #to_schema ⇒ Object
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
#attributes ⇒ Object (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, = {}, &blk) return attributes[name] = { type: self.class.new(&blk) }.merge().compact if block_given? attributes[name] = { type: :string }.merge().compact end |
#to_schema ⇒ Object
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 |