Class: ApiResource::Finders::AbstractFinder
- Inherits:
-
Object
- Object
- ApiResource::Finders::AbstractFinder
- Defined in:
- lib/api_resource/finders/abstract_finder.rb
Direct Known Subclasses
MultiObjectAssociationFinder, ResourceFinder, SingleFinder, SingleObjectAssociationFinder
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#found ⇒ Object
readonly
Returns the value of attribute found.
-
#internal_object ⇒ Object
readonly
Returns the value of attribute internal_object.
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
- #all(*args) ⇒ Object
-
#headers ⇒ Hash
Return the headers for our response from the server.
-
#initialize(klass, condition) ⇒ AbstractFinder
constructor
A new instance of AbstractFinder.
-
#instance_of?(klass) ⇒ Boolean
Allows us to respond correctly to instance_of? based on our internal_object.
-
#is_a?(klass) ⇒ Boolean
Allows us to respond correctly to is_a? based on our internal_object.
-
#kind_of?(klass) ⇒ Boolean
Allows us to respond correctly to kind_of? based on our internal_object.
- #load ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
proxy unknown methods to the internal_object.
-
#offset ⇒ Fixnum
Offset returned from the server.
-
#paginated? ⇒ Boolean
Is this a paginated find?.
-
#response ⇒ ApiResource::Response
Getter for our response from the server.
-
#total_entries ⇒ Fixnum
Total number of entries the server has told us are in our collection.
Constructor Details
#initialize(klass, condition) ⇒ AbstractFinder
Returns a new instance of AbstractFinder.
14 15 16 17 18 19 20 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 14 def initialize(klass, condition) @klass = klass @condition = condition @found = false @klass.load_resource_definition end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
proxy unknown methods to the internal_object
121 122 123 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 121 def method_missing(method, *args, &block) self.internal_object.send(method, *args, &block) end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 8 def condition @condition end |
#found ⇒ Object (readonly)
Returns the value of attribute found.
9 10 11 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 9 def found @found end |
#internal_object ⇒ Object (readonly)
Returns the value of attribute internal_object.
9 10 11 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 9 def internal_object @internal_object end |
#klass ⇒ Object
Returns the value of attribute klass.
8 9 10 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 8 def klass @klass end |
Instance Method Details
#all(*args) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 112 def all(*args) if args.blank? self.internal_object else self.klass.send(:all, *args) end end |
#headers ⇒ Hash
Return the headers for our response from the server
60 61 62 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 60 def headers self.response.try(:headers) end |
#instance_of?(klass) ⇒ Boolean
Allows us to respond correctly to instance_of? based on our internal_object
29 30 31 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 29 def instance_of?(klass) super || self.internal_object.instance_of?(klass) end |
#is_a?(klass) ⇒ Boolean
Allows us to respond correctly to is_a? based on our internal_object
40 41 42 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 40 def is_a?(klass) super || self.internal_object.is_a?(klass) end |
#kind_of?(klass) ⇒ Boolean
Allows us to respond correctly to kind_of? based on our internal_object
51 52 53 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 51 def kind_of?(klass) self.is_a?(klass) end |
#load ⇒ Object
73 74 75 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 73 def load raise NotImplementedError("Must be defined in a subclass") end |
#offset ⇒ Fixnum
Offset returned from the server
81 82 83 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 81 def offset self.headers.try(:[], 'ApiResource-Offset').to_i end |
#paginated? ⇒ Boolean
Is this a paginated find?
89 90 91 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 89 def paginated? @condition.paginated? end |
#response ⇒ ApiResource::Response
Getter for our response from the server
106 107 108 109 110 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 106 def response @response ||= begin self.klass.connection.get(self.build_load_path) end end |
#total_entries ⇒ Fixnum
Total number of entries the server has told us are in our collection
98 99 100 |
# File 'lib/api_resource/finders/abstract_finder.rb', line 98 def total_entries self.headers.try(:[], 'ApiResource-Total-Entries').to_i end |