Class: Restspec::Schema::SingleSchemaDSL
- Inherits:
-
Object
- Object
- Restspec::Schema::SingleSchemaDSL
- Includes:
- Types::TypeMethods
- Defined in:
- lib/restspec/schema/dsl.rb
Overview
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.
Instance Attribute Summary collapse
-
#schema ⇒ Schema
readonly
The current schema.
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ Object
Creates an attribute and saving it into the schema.
-
#include_attributes(name) ⇒ Object
Includes a mixin generated by the DSL#mixin function into the schema.
-
#initialize(name, options = {}, mixins = {}) ⇒ SingleSchemaDSL
constructor
A new instance of SingleSchemaDSL.
Methods included from Types::TypeMethods
#array, #boolean, #date, #datetime, #decimal, #decimal_string, #embedded_schema, #hash, #integer, #null, #one_of, #schema_id, #string
Constructor Details
#initialize(name, options = {}, mixins = {}) ⇒ SingleSchemaDSL
Returns a new instance of SingleSchemaDSL.
70 71 72 73 |
# File 'lib/restspec/schema/dsl.rb', line 70 def initialize(name, = {}, mixins = {}) self.schema = Schema.new(name, ) self.mixins = mixins end |
Instance Attribute Details
#schema ⇒ Schema
Returns the current schema.
68 69 70 |
# File 'lib/restspec/schema/dsl.rb', line 68 def schema @schema end |
Instance Method Details
#attribute(name, type, options = {}) ⇒ Object
Creates an attribute and saving it into the schema. It uses the same parameters as the Attribute#initialize method.
86 87 88 89 |
# File 'lib/restspec/schema/dsl.rb', line 86 def attribute(name, type, = {}) new_attribute = Attribute.new(name, type, ) schema.attributes[name.to_s] = new_attribute end |
#include_attributes(name) ⇒ Object
Includes a mixin generated by the DSL#mixin function into the schema.
97 98 99 |
# File 'lib/restspec/schema/dsl.rb', line 97 def include_attributes(name) self.instance_eval &mixins.fetch(name) end |