Class: JSONAPI::Consumer::Schema
- Inherits:
-
Object
- Object
- JSONAPI::Consumer::Schema
- Defined in:
- lib/jsonapi/consumer/schema.rb
Defined Under Namespace
Modules: Types Classes: Property, TypeFactory
Class Method Summary collapse
Instance Method Summary collapse
-
#add(name, options) ⇒ void
Add a property to the schema.
- #each_property(&block) ⇒ Object (also: #each)
-
#find(property_name) ⇒ Property?
(also: #[])
Look up a property by name.
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
-
#size ⇒ Fixnum
(also: #length)
How many properties are defined.
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
107 108 109 |
# File 'lib/jsonapi/consumer/schema.rb', line 107 def initialize @properties = {} end |
Class Method Details
.register(type_hash) ⇒ Object
148 149 150 |
# File 'lib/jsonapi/consumer/schema.rb', line 148 def register(type_hash) TypeFactory.register(type_hash) end |
Instance Method Details
#add(name, options) ⇒ void
This method returns an undefined value.
Add a property to the schema
118 119 120 |
# File 'lib/jsonapi/consumer/schema.rb', line 118 def add(name, ) @properties[name.to_sym] = Property.new(name.to_sym, [:type], [:default]) end |
#each_property(&block) ⇒ Object Also known as: each
131 132 133 |
# File 'lib/jsonapi/consumer/schema.rb', line 131 def each_property(&block) @properties.values.each(&block) end |
#find(property_name) ⇒ Property? Also known as: []
Look up a property by name
141 142 143 |
# File 'lib/jsonapi/consumer/schema.rb', line 141 def find(property_name) @properties[property_name.to_sym] end |
#size ⇒ Fixnum Also known as: length
How many properties are defined
125 126 127 |
# File 'lib/jsonapi/consumer/schema.rb', line 125 def size @properties.size end |