class Restspec::Schema::Schema
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.
Attributes
attributes[RW]
The set of attributes that conforms the schema.
intention[RW]
TODO: Document
name[RW]
The schema identifier.
original_schema[RW]
root[RW]
The root raw value
Public Class Methods
new(name, options = {})
click to toggle source
@param name [Symbol] The name of the schema @param options [Hash] Some options:
- root: If the schema should have a root `{ schema: }` around the object. If this attribute is a symbol or string, that will be the schema root to use.
@return a new {Restspec::Schema::Schema Schema} object
# File lib/restspec/schema/schema.rb, line 25 def initialize(name, options = {}) self.name = name self.attributes = {} self.root = options[:root] end
Public Instance Methods
attributes_for_intention()
click to toggle source
# 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: [])
click to toggle source
@param without [Array] An array of attributes that should be removed from the schema.
This shouldn't be used without cloning first, to avoid modifying a schema used elsewhere.
# 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?()
click to toggle source
@return [true, false] if the schema must include a root.
# File lib/restspec/schema/schema.rb, line 49 def root? !!root end
root_name()
click to toggle source
# File lib/restspec/schema/schema.rb, line 53 def root_name root == true ? name.to_sym : root.to_sym end