Class: ActiveSP::Associations::AssociationProxy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/activesp/associations.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, &element_getter) ⇒ AssociationProxy

Returns a new instance of AssociationProxy.



35
36
37
38
# File 'lib/activesp/associations.rb', line 35

def initialize(object, &element_getter)
  @object = object
  @element_getter = element_getter
end

Instance Method Details

#countObject



53
54
55
# File 'lib/activesp/associations.rb', line 53

def count
  inject(0) { |cnt, _| cnt + 1 }
end

#each(&blk) ⇒ Object



40
41
42
# File 'lib/activesp/associations.rb', line 40

def each(&blk)
  @element_getter.call(blk)
end

#firstObject



44
45
46
47
# File 'lib/activesp/associations.rb', line 44

def first
  each { |element| return element }
  nil
end

#lastObject



49
50
51
# File 'lib/activesp/associations.rb', line 49

def last
  inject { |_, element| element }
end