Class: Restspec::Schema::Schema
- Inherits:
-
Object
- Object
- Restspec::Schema::Schema
- Defined in:
- lib/restspec/schema/schema.rb
Overview
A schema is a collection of attributes that defines how the data passed through the API should be formed. In REST, they are the representation of the resources the REST API returns.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The set of attributes that conforms the schema.
-
#intention ⇒ Object
TODO: Document.
-
#name ⇒ Object
readonly
The schema identifier.
-
#original_schema ⇒ Object
Returns the value of attribute original_schema.
-
#root ⇒ Object
readonly
The root raw value.
Instance Method Summary collapse
- #attributes_for_intention ⇒ Object
- #extend_with(without: []) ⇒ Object
-
#initialize(name, options = {}) ⇒ Object
constructor
A new Schema object.
-
#root? ⇒ true, false
If the schema must include a root.
- #root_name ⇒ Object
Constructor Details
Instance Attribute Details
#attributes ⇒ Object
The set of attributes that conforms the schema.
11 12 13 |
# File 'lib/restspec/schema/schema.rb', line 11 def attributes @attributes end |
#intention ⇒ Object
TODO: Document
17 18 19 |
# File 'lib/restspec/schema/schema.rb', line 17 def intention @intention end |
#name ⇒ Object
The schema identifier.
8 9 10 |
# File 'lib/restspec/schema/schema.rb', line 8 def name @name end |
#original_schema ⇒ Object
Returns the value of attribute original_schema.
18 19 20 |
# File 'lib/restspec/schema/schema.rb', line 18 def original_schema @original_schema end |
#root ⇒ Object
The root raw value
14 15 16 |
# File 'lib/restspec/schema/schema.rb', line 14 def root @root end |
Instance Method Details
#attributes_for_intention ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/restspec/schema/schema.rb', line 39 def attributes_for_intention return attributes if intention.blank? attributes.inject({}) do |hash, (name, attribute)| attribute.can?(intention) ? hash.merge(name => attribute) : hash end end |
#extend_with(without: []) ⇒ Object
34 35 36 37 |
# File 'lib/restspec/schema/schema.rb', line 34 def extend_with(without: []) without.each { |attribute_name| attributes.delete(attribute_name.to_s) } self end |
#root? ⇒ true, false
Returns if the schema must include a root.
49 50 51 |
# File 'lib/restspec/schema/schema.rb', line 49 def root? !!root end |