class Sinatra::Schema::DSL::Definitions

Attributes

definition[RW]
options[RW]
resource[RW]
targets[RW]

Public Class Methods

new(resource, targets) click to toggle source
# 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

Public Instance Methods

[](id) click to toggle source

support nested properties. eg: property.text :bar

# 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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source

support references to other properties that are lazily evaluated

# File lib/sinatra/schema/dsl/definitions.rb, line 39
def ref(id, options={})
  add Reference.new(resource, id, options)
end
text(id, options={}) click to toggle source
# 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={}) click to toggle source
# File lib/sinatra/schema/dsl/definitions.rb, line 48
def uuid(id, options={})
  options.merge!(id: id, type: "uuid")
  add Definition.new(options)
end

Protected Instance Methods

add(definition) click to toggle source
# File lib/sinatra/schema/dsl/definitions.rb, line 64
def add(definition)
  targets.each do |target|
    target[definition.id] ||= definition
  end
end