Class: ApiResource::Conditions::AbstractCondition
- Inherits:
-
Object
- Object
- ApiResource::Conditions::AbstractCondition
- Includes:
- Enumerable
- Defined in:
- lib/api_resource/conditions/abstract_condition.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#included_objects ⇒ Object
readonly
Returns the value of attribute included_objects.
-
#internal_object ⇒ Object
readonly
Returns the value of attribute internal_object.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#remote_path ⇒ Object
readonly
Returns the value of attribute remote_path.
Instance Method Summary collapse
- #all(*args) ⇒ Object
- #blank_conditions? ⇒ Boolean
- #each(&block) ⇒ Object
- #eager_load? ⇒ Boolean
- #expires_in(time) ⇒ Object
-
#find(*args) ⇒ Object
implement find that accepts an optional condition object.
-
#initialize(args, klass) ⇒ AbstractCondition
constructor
need to figure out what to do with args in the subclass, parent is the set of scopes we have right now.
-
#load ⇒ Object
TODO: review the hierarchy that makes this necessary consider changing it to alias method.
- #loaded? ⇒ Boolean
-
#merge!(cond) ⇒ Object
TODO: Remove the bang, this doesn’t modify anything.
- #method_missing(sym, *args, &block) ⇒ Object
- #reload ⇒ Object
- #to_hash ⇒ Object
- #to_query ⇒ Object
Constructor Details
#initialize(args, klass) ⇒ AbstractCondition
need to figure out what to do with args in the subclass, parent is the set of scopes we have right now
22 23 24 25 26 27 28 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 22 def initialize(args, klass) @klass = klass @conditions = args.with_indifferent_access @klass.load_resource_definition end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 92 def method_missing(sym, *args, &block) result = @klass.send(sym, *args, &block) if result.is_a?(ApiResource::Conditions::AbstractCondition) return self.dup.merge!(result) else return result end end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
9 10 11 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 9 def association @association end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
9 10 11 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 9 def conditions @conditions end |
#included_objects ⇒ Object (readonly)
Returns the value of attribute included_objects.
9 10 11 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 9 def included_objects @included_objects end |
#internal_object ⇒ Object (readonly)
Returns the value of attribute internal_object.
9 10 11 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 9 def internal_object @internal_object end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
9 10 11 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 9 def klass @klass end |
#remote_path ⇒ Object (readonly)
Returns the value of attribute remote_path.
9 10 11 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 9 def remote_path @remote_path end |
Instance Method Details
#all(*args) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 61 def all(*args) if args.blank? self.internal_object else self.find(*([:all] + args)) end end |
#blank_conditions? ⇒ Boolean
34 35 36 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 34 def blank_conditions? self.conditions.blank? end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 30 def each(&block) self.internal_object.each(&block) end |
#eager_load? ⇒ Boolean
38 39 40 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 38 def eager_load? self.included_objects.present? end |
#expires_in(time) ⇒ Object
102 103 104 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 102 def expires_in(time) ApiResource::Decorators::CachingDecorator.new(self, time) end |
#find(*args) ⇒ Object
implement find that accepts an optional condition object
71 72 73 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 71 def find(*args) self.klass.find(*(args + [self])) end |
#load ⇒ Object
TODO: review the hierarchy that makes this necessary consider changing it to alias method
77 78 79 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 77 def load self.internal_object end |
#loaded? ⇒ Boolean
81 82 83 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 81 def loaded? @loaded == true end |
#merge!(cond) ⇒ Object
TODO: Remove the bang, this doesn’t modify anything
107 108 109 110 111 112 113 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 107 def merge!(cond) @included_objects = (@included_objects || []).concat(cond.included_objects || []).uniq @conditions = @conditions.merge(cond.to_hash) @association = cond.association || self.association @remote_path = self.remote_path ? self.remote_path : cond.remote_path return self end |
#reload ⇒ Object
85 86 87 88 89 90 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 85 def reload if instance_variable_defined?(:@internal_object) remove_instance_variable(:@internal_object) end @loaded = false end |
#to_hash ⇒ Object
50 51 52 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 50 def to_hash self.conditions.to_hash end |
#to_query ⇒ Object
46 47 48 |
# File 'lib/api_resource/conditions/abstract_condition.rb', line 46 def to_query CGI.unescape(to_query_safe_hash(self.to_hash).to_query) end |