Class: Horza::Entities::Collection

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Defined in:
lib/horza/entities/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ Collection

Returns a new instance of Collection.



6
7
8
# File 'lib/horza/entities/collection.rb', line 6

def initialize(collection)
  @collection = collection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, &block) ⇒ Object (private)



16
17
18
19
20
21
22
23
24
25
# File 'lib/horza/entities/collection.rb', line 16

def method_missing(method, &block)
  if [:length, :size, :empty?, :present?].include? method
    @collection.send(method)
  elsif [:first, :last, :pop].include? method
    result = @collection.send(method)
    singular_entity(result) unless result.nil?
  elsif [:each, :map, :collect]
    enum_method(method, &block)
  end
end

Instance Method Details

#[](index) ⇒ Object



10
11
12
# File 'lib/horza/entities/collection.rb', line 10

def [](index)
  singular_entity(@collection[index])
end