Module: PipeLineDealer::Collection::Concerns::Fetching
- Extended by:
- ActiveSupport::Concern
- Included in:
- PipeLineDealer::Collection
- Defined in:
- lib/pipe_line_dealer/collection/concerns/fetching.rb
Instance Method Summary collapse
- #all ⇒ Object
- #each(&block) ⇒ Object
-
#find(id) ⇒ Object
TODO: Not speced.
- #first ⇒ Object
- #limit(lmt) ⇒ Object
- #on_new_defaults(opts) ⇒ Object
- #to_a ⇒ Object
- #where(opts) ⇒ Object
Instance Method Details
#all ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 17 def all if @options[:cached] @client.connection.cache(@options[:cache_key]) { self.to_a } else self end end |
#each(&block) ⇒ Object
40 41 42 43 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 40 def each &block = @options.dup ResultsFetcher.new(self, ).each &block end |
#find(id) ⇒ Object
TODO: Not speced
46 47 48 49 50 51 52 53 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 46 def find id status, result = @client.connection.get(collection_url + "/#{id}.json", {}) if status == 200 @klass.new(collection: self, persisted: true, attributes: result) else raise Error::NotFound end end |
#first ⇒ Object
29 30 31 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 29 def first self.limit(1).to_a.first end |
#limit(lmt) ⇒ Object
25 26 27 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 25 def limit(lmt) refine(limit: lmt) end |
#on_new_defaults(opts) ⇒ Object
12 13 14 15 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 12 def on_new_defaults(opts) = @options.merge(new_defaults: opts) self.class.new(@client, ) end |
#to_a ⇒ Object
33 34 35 36 37 38 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 33 def to_a array = [] self.each { |item| array << item } array end |
#where(opts) ⇒ Object
7 8 9 10 |
# File 'lib/pipe_line_dealer/collection/concerns/fetching.rb', line 7 def where(opts) = @options.merge(where: opts) self.class.new(@client, ) end |