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.
-
#_type ⇒ Object
readonly
Returns the value of attribute _type.
-
#_use_links ⇒ Object
readonly
Returns the value of attribute _use_links.
-
#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
- #type(type) ⇒ Object
- #use_links(yesno) ⇒ 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 |
#_type ⇒ Object (readonly)
Returns the value of attribute _type.
6 7 8 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 6 def _type @_type end |
#_use_links ⇒ Object (readonly)
Returns the value of attribute _use_links.
5 6 7 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 5 def _use_links @_use_links end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 7 def fields @fields end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
8 9 10 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 8 def relationships @relationships end |
Instance Method Details
#attribute(attr) ⇒ Object
16 17 18 19 20 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 16 def attribute(attr) @fields ||= [] @fields << attr create_accessor_methods(attr) end |
#attributes(*attrs) ⇒ Object
10 11 12 13 14 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 10 def attributes(*attrs) attrs.each do |attr| attribute(attr) end end |
#has_many(object_name, options = {}) ⇒ Object
26 27 28 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 26 def has_many(object_name, ={}) add_relationship(object_name, :many, ) end |
#has_one(object_name, options = {}) ⇒ Object
22 23 24 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 22 def has_one(object_name, ={}) add_relationship(object_name, :one, ) end |
#id_field(key) ⇒ Object
30 31 32 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 30 def id_field(key) @_id_field = key end |
#type(type) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 34 def type(type) # allow falling back to default if we reallly want to if type.blank? @_type = nil else @_type = type.to_s end end |
#use_links(yesno) ⇒ Object
43 44 45 |
# File 'lib/json_api_ruby/resources/dsl.rb', line 43 def use_links(yesno) @_use_links = yesno end |