Class: JsonApiResource::Associations::Base
- Inherits:
-
Object
- Object
- JsonApiResource::Associations::Base
- Includes:
- Errors
- Defined in:
- lib/json_api_resource/associations/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #callable?(root_insatnce) ⇒ Boolean
- #default_nil ⇒ Object
-
#initialize(associated_class, name, opts = {}) ⇒ Base
constructor
A new instance of Base.
-
#klass ⇒ Object
klass has to be lazy initted for circular dependencies.
- #opts ⇒ Object
- #post_process(value) ⇒ Object
- #query(root_insatnce) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(associated_class, name, opts = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/json_api_resource/associations/base.rb', line 7 def initialize(associated_class, name, opts = {}) self.name = name.to_sym self.root = associated_class @opts = opts.merge( skip_pagination: true ) self.action = @opts.delete :action do default_action end self.key = @opts.delete :foreign_key do server_key end self.key = self.key.try :to_sym end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/json_api_resource/associations/base.rb', line 5 def action @action end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/json_api_resource/associations/base.rb', line 5 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/json_api_resource/associations/base.rb', line 5 def name @name end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/json_api_resource/associations/base.rb', line 5 def root @root end |
Instance Method Details
#callable?(root_insatnce) ⇒ Boolean
27 28 29 |
# File 'lib/json_api_resource/associations/base.rb', line 27 def callable?( root_insatnce ) raise NotImplementedError end |
#default_nil ⇒ Object
31 32 33 |
# File 'lib/json_api_resource/associations/base.rb', line 31 def default_nil raise NotImplementedError end |
#klass ⇒ Object
klass has to be lazy initted for circular dependencies
36 37 38 39 40 41 |
# File 'lib/json_api_resource/associations/base.rb', line 36 def klass @klass ||= begin klass = @opts.delete(:class_name).try :constantize klass || @opts.delete( :class ) do derived_class end end end |
#opts ⇒ Object
47 48 49 |
# File 'lib/json_api_resource/associations/base.rb', line 47 def opts @opts.except *ASSOCIATION_OPTS end |
#post_process(value) ⇒ Object
43 44 45 |
# File 'lib/json_api_resource/associations/base.rb', line 43 def post_process( value ) value end |
#query(root_insatnce) ⇒ Object
23 24 25 |
# File 'lib/json_api_resource/associations/base.rb', line 23 def query( root_insatnce ) raise NotImplementedError end |
#type ⇒ Object
19 20 21 |
# File 'lib/json_api_resource/associations/base.rb', line 19 def type raise NotImplementedError end |