Class: ActiveRecordSamplooper::ArrayLooper

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_samplooper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ ArrayLooper

Returns a new instance of ArrayLooper.



24
25
26
# File 'lib/active_record_samplooper.rb', line 24

def initialize(array)
  self.array = array.dup
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



14
15
16
# File 'lib/active_record_samplooper.rb', line 14

def array
  @array
end

Class Method Details

.call(*args) ⇒ Object



18
19
20
# File 'lib/active_record_samplooper.rb', line 18

def call(*args)
  new(*args)
end

Instance Method Details

#find(id) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


29
30
31
32
# File 'lib/active_record_samplooper.rb', line 29

def find(id)
  raise ActiveRecord::RecordNotFound unless id
  array[id - 1] || raise(Gone, id)
end

#pluckObject



35
36
37
# File 'lib/active_record_samplooper.rb', line 35

def pluck(*)
  (1..array.size).to_a
end