Class: Sinatra::Schema::DSL::Definitions
- Inherits:
-
Object
- Object
- Sinatra::Schema::DSL::Definitions
- Defined in:
- lib/sinatra/schema/dsl/definitions.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#options ⇒ Object
Returns the value of attribute options.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#targets ⇒ Object
Returns the value of attribute targets.
Instance Method Summary collapse
-
#[](id) ⇒ Object
support nested properties.
- #bool(id, options = {}) ⇒ Object
- #datetime(id, options = {}) ⇒ Object
- #email(id, options = {}) ⇒ Object
-
#initialize(resource, targets) ⇒ Definitions
constructor
A new instance of Definitions.
- #int(id, options = {}) ⇒ Object
- #object(id, options = {}) ⇒ Object
-
#ref(id, options = {}) ⇒ Object
support references to other properties that are lazily evaluated.
- #text(id, options = {}) ⇒ Object
- #uuid(id, options = {}) ⇒ Object
Constructor Details
#initialize(resource, targets) ⇒ Definitions
Returns a new instance of Definitions.
7 8 9 10 11 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 7 def initialize(resource, targets) @resource = resource # array of hashes to receive the definition, first is the resource defs @targets = targets end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
5 6 7 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 5 def definition @definition end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 5 def @options end |
#resource ⇒ Object
Returns the value of attribute resource.
5 6 7 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 5 def resource @resource end |
#targets ⇒ Object
Returns the value of attribute targets.
5 6 7 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 5 def targets @targets end |
Instance Method Details
#[](id) ⇒ Object
support nested properties. eg: property.text :bar
54 55 56 57 58 59 60 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 54 def [](id) # make sure all targets have a sub-hash for this nested def targets.each { |h| h[id] ||= {} } # return a new DSL with updated targets so it can be chained Definitions.new(resource, targets.map { |h| h[id] }) end |
#bool(id, options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 13 def bool(id, ={}) .merge!(id: id, type: "boolean") add Definition.new() end |
#datetime(id, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 18 def datetime(id, ={}) .merge!(id: id, type: "datetime") add Definition.new() end |
#email(id, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 23 def email(id, ={}) .merge!(id: id, type: "email") add Definition.new() end |
#int(id, options = {}) ⇒ Object
28 29 30 31 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 28 def int(id, ={}) .merge!(id: id, type: "integer") add Definition.new() end |
#object(id, options = {}) ⇒ Object
33 34 35 36 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 33 def object(id, ={}) .merge!(id: id, type: "object") add Definition.new() end |
#ref(id, options = {}) ⇒ Object
support references to other properties that are lazily evaluated
39 40 41 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 39 def ref(id, ={}) add Reference.new(resource, id, ) end |
#text(id, options = {}) ⇒ Object
43 44 45 46 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 43 def text(id, ={}) .merge!(id: id, type: "string") add Definition.new() end |
#uuid(id, options = {}) ⇒ Object
48 49 50 51 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 48 def uuid(id, ={}) .merge!(id: id, type: "uuid") add Definition.new() end |