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.
-
#ref(id, ref_to = nil) ⇒ 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
44 45 46 47 48 49 50 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 44 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 |
#ref(id, ref_to = nil) ⇒ Object
support references to other properties that are lazily evaluated
29 30 31 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 29 def ref(id, ref_to=nil) add Reference.new(resource, id, ref_to) end |
#text(id, options = {}) ⇒ Object
33 34 35 36 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 33 def text(id, ={}) .merge!(id: id, type: "string") add Definition.new() end |
#uuid(id, options = {}) ⇒ Object
38 39 40 41 |
# File 'lib/sinatra/schema/dsl/definitions.rb', line 38 def uuid(id, ={}) .merge!(id: id, type: "uuid") add Definition.new() end |