class Restspec::Schema::SingleSchemaDSL

The DSL to use inside `schema` and `mixin` blocks of a {DSL} instance block. It defines specific things of a schema or a group of them.

Attributes

mixins[RW]
schema[RW]

@return {Schema} the current schema

Public Class Methods

new(name, options = {}, mixins = {}) click to toggle source
# File lib/restspec/schema/dsl.rb, line 70
def initialize(name, options = {}, mixins = {})
  self.schema = Schema.new(name, options)
  self.mixins = mixins
end

Public Instance Methods

attribute(name, type, options = {}) click to toggle source

Creates an attribute and saving it into the schema. It uses the same parameters as the {Attribute#initialize} method.

@example

schema :books do
 attribute :title, string
 attribute :created_at, datetime, :for => [:response]
end

@param (see Attribute#initialize)

# File lib/restspec/schema/dsl.rb, line 86
def attribute(name, type, options = {})
  new_attribute = Attribute.new(name, type, options)
  schema.attributes[name.to_s] = new_attribute
end
include_attributes(name) click to toggle source

Includes a mixin generated by the {DSL#mixin} function into the schema.

@example (see DSL#mixin)

@param name [Symbol] the mixin name

# File lib/restspec/schema/dsl.rb, line 97
def include_attributes(name)
  self.instance_eval &mixins.fetch(name)
end