Class: Sinatra::Schema::DSL::Definitions

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/schema/dsl/definitions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#definitionObject

Returns the value of attribute definition.



5
6
7
# File 'lib/sinatra/schema/dsl/definitions.rb', line 5

def definition
  @definition
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/sinatra/schema/dsl/definitions.rb', line 5

def options
  @options
end

#resourceObject

Returns the value of attribute resource.



5
6
7
# File 'lib/sinatra/schema/dsl/definitions.rb', line 5

def resource
  @resource
end

#targetsObject

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, options={})
  options.merge!(id: id, type: "boolean")
  add Definition.new(options)
end

#datetime(id, options = {}) ⇒ Object



18
19
20
21
# File 'lib/sinatra/schema/dsl/definitions.rb', line 18

def datetime(id, options={})
  options.merge!(id: id, type: "datetime")
  add Definition.new(options)          
end

#email(id, options = {}) ⇒ Object



23
24
25
26
# File 'lib/sinatra/schema/dsl/definitions.rb', line 23

def email(id, options={})
  options.merge!(id: id, type: "email")
  add Definition.new(options)
end

#int(id, options = {}) ⇒ Object



28
29
30
31
# File 'lib/sinatra/schema/dsl/definitions.rb', line 28

def int(id, options={})
  options.merge!(id: id, type: "integer")
  add Definition.new(options)
end

#object(id, options = {}) ⇒ Object



33
34
35
36
# File 'lib/sinatra/schema/dsl/definitions.rb', line 33

def object(id, options={})
  options.merge!(id: id, type: "object")
  add Definition.new(options)
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, options={})
  add Reference.new(resource, id, options)
end

#text(id, options = {}) ⇒ Object



43
44
45
46
# File 'lib/sinatra/schema/dsl/definitions.rb', line 43

def text(id, options={})
  options.merge!(id: id, type: "string")
  add Definition.new(options)
end

#uuid(id, options = {}) ⇒ Object



48
49
50
51
# File 'lib/sinatra/schema/dsl/definitions.rb', line 48

def uuid(id, options={})
  options.merge!(id: id, type: "uuid")
  add Definition.new(options)
end