Module: JsonApi::Resources::DSL
- Included in:
- JsonApi::Resource
- Defined in:
- lib/json_api_ruby/resources/dsl.rb
Instance Attribute Summary collapse
-
#_id_field ⇒ Object
readonly
Returns the value of attribute _id_field.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
Instance Method Summary collapse
- #attribute(attr) ⇒ Object
- #attributes(*attrs) ⇒ Object
- #has_many(object_name, options = {}) ⇒ Object
- #has_one(object_name, options = {}) ⇒ Object
- #id_field(key) ⇒ Object
Instance Attribute Details
#_id_field ⇒ Object (readonly)
Returns the value of attribute _id_field.
4 5 6 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 4 def _id_field @_id_field end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
5 6 7 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 5 def fields @fields end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
6 7 8 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 6 def relationships @relationships end |
Instance Method Details
#attribute(attr) ⇒ Object
14 15 16 17 18 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 14 def attribute(attr) @fields ||= [] @fields << attr create_accessor_methods(attr) end |
#attributes(*attrs) ⇒ Object
8 9 10 11 12 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 8 def attributes(*attrs) attrs.each do |attr| attribute(attr) end end |
#has_many(object_name, options = {}) ⇒ Object
24 25 26 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 24 def has_many(object_name, ={}) add_relationship(object_name, :many, ) end |
#has_one(object_name, options = {}) ⇒ Object
20 21 22 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 20 def has_one(object_name, ={}) add_relationship(object_name, :one, ) end |
#id_field(key) ⇒ Object
28 29 30 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 28 def id_field(key) @_id_field = key end |