Class: SmartPreloads::List
- Inherits:
-
Object
- Object
- SmartPreloads::List
- Includes:
- Enumerable
- Defined in:
- lib/smart_preloads/list.rb
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #[](idx) ⇒ Object
- #each ⇒ Object
-
#initialize(collection, loader: nil) ⇒ List
constructor
A new instance of List.
- #size ⇒ Object
Constructor Details
#initialize(collection, loader: nil) ⇒ List
Returns a new instance of List.
5 6 7 8 |
# File 'lib/smart_preloads/list.rb', line 5 def initialize(collection, loader: nil) @collection = collection @loader = loader || Loader.new(@collection) end |
Instance Method Details
#+(other) ⇒ Object
28 29 30 |
# File 'lib/smart_preloads/list.rb', line 28 def +(other) to_a + other.to_a end |
#==(other) ⇒ Object
20 21 22 |
# File 'lib/smart_preloads/list.rb', line 20 def ==(other) to_a == other end |
#[](idx) ⇒ Object
32 33 34 |
# File 'lib/smart_preloads/list.rb', line 32 def [](idx) to_a[idx] end |
#each ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/smart_preloads/list.rb', line 10 def each loaded_collection.each do |resource| if resource.is_a?(Item) yield resource else yield Item.new(resource, loader: @loader) end end end |
#size ⇒ Object
24 25 26 |
# File 'lib/smart_preloads/list.rb', line 24 def size to_a.size end |