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, 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, mixins = {}) ⇒ SingleSchemaDSL
Returns a new instance of SingleSchemaDSL.
69 70 71 72 |
# File 'lib/restspec/schema/dsl.rb', line 69 def initialize(name, mixins = {}) self.schema = Schema.new(name) self.mixins = mixins end |
Instance Attribute Details
#schema ⇒ Schema
Returns the current schema.
67 68 69 |
# File 'lib/restspec/schema/dsl.rb', line 67 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.
85 86 87 88 |
# File 'lib/restspec/schema/dsl.rb', line 85 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.
96 97 98 |
# File 'lib/restspec/schema/dsl.rb', line 96 def include_attributes(name) self.instance_eval &mixins.fetch(name) end |