Class: Lurch::Collection
- Inherits:
-
Object
- Object
- Lurch::Collection
- Includes:
- Enumerable
- Defined in:
- lib/lurch/collection.rb
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #each_page(&block) ⇒ Object
- #fetch ⇒ Object
- #first? ⇒ Boolean
- #first_collection ⇒ Object
-
#initialize(resources, paginator) ⇒ Collection
constructor
A new instance of Collection.
- #inspect ⇒ Object
- #last? ⇒ Boolean
- #last_collection ⇒ Object
- #loaded? ⇒ Boolean
- #next? ⇒ Boolean
- #next_collection ⇒ Object
- #page_count ⇒ Object
- #page_size ⇒ Object
- #prev? ⇒ Boolean
- #prev_collection ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(resources, paginator) ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 |
# File 'lib/lurch/collection.rb', line 7 def initialize(resources, paginator) @resources = resources @paginator = paginator end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
5 6 7 |
# File 'lib/lurch/collection.rb', line 5 def resources @resources end |
Instance Method Details
#each(&block) ⇒ Object
20 21 22 |
# File 'lib/lurch/collection.rb', line 20 def each(&block) block_given? ? enum.each(&block) : enum end |
#each_page(&block) ⇒ Object
24 25 26 |
# File 'lib/lurch/collection.rb', line 24 def each_page(&block) block_given? ? page_enum.each(&block) : page_enum end |
#fetch ⇒ Object
16 17 18 |
# File 'lib/lurch/collection.rb', line 16 def fetch self end |
#first? ⇒ Boolean
68 69 70 |
# File 'lib/lurch/collection.rb', line 68 def first? @paginator ? @paginator.first? : false end |
#first_collection ⇒ Object
50 51 52 53 |
# File 'lib/lurch/collection.rb', line 50 def first_collection return @first_collection if defined?(@first_collection) @first_collection = @paginator ? @paginator.first_collection : nil end |
#inspect ⇒ Object
76 77 78 79 80 81 |
# File 'lib/lurch/collection.rb', line 76 def inspect suffix = @resources.first ? "[#{Inflector.classify(@resources.first.type)}]" : "" inspection = size ? ["size: #{size}"] : [] inspection << ["pages: #{page_count}"] if page_count "#<#{self.class}#{suffix} #{inspection.join(', ')}>" end |
#last? ⇒ Boolean
72 73 74 |
# File 'lib/lurch/collection.rb', line 72 def last? @paginator ? @paginator.last? : false end |
#last_collection ⇒ Object
55 56 57 58 |
# File 'lib/lurch/collection.rb', line 55 def last_collection return @last_collection if defined?(@last_collection) @last_collection = @paginator ? @paginator.last_collection : nil end |
#loaded? ⇒ Boolean
12 13 14 |
# File 'lib/lurch/collection.rb', line 12 def loaded? true end |
#next? ⇒ Boolean
60 61 62 |
# File 'lib/lurch/collection.rb', line 60 def next? @paginator ? @paginator.next? : false end |
#next_collection ⇒ Object
40 41 42 43 |
# File 'lib/lurch/collection.rb', line 40 def next_collection return @next_collection if defined?(@next_collection) @next_collection = @paginator ? @paginator.next_collection : nil end |
#page_count ⇒ Object
36 37 38 |
# File 'lib/lurch/collection.rb', line 36 def page_count @paginator.page_count if @paginator end |
#page_size ⇒ Object
32 33 34 |
# File 'lib/lurch/collection.rb', line 32 def page_size @resources.size end |
#prev? ⇒ Boolean
64 65 66 |
# File 'lib/lurch/collection.rb', line 64 def prev? @paginator ? @paginator.prev? : false end |
#prev_collection ⇒ Object
45 46 47 48 |
# File 'lib/lurch/collection.rb', line 45 def prev_collection return @prev_collection if defined?(@prev_collection) @prev_collection = @paginator ? @paginator.prev_collection : nil end |
#size ⇒ Object
28 29 30 |
# File 'lib/lurch/collection.rb', line 28 def size @paginator ? @paginator.record_count : @resources.size end |