Class: Shiftable::ShiftingRelation

Inherits:
Shifting
  • Object
show all
Includes:
Enumerable
Defined in:
lib/shiftable/shifting_relation.rb

Overview

Gets data to be shifted

Instance Attribute Summary

Attributes inherited from Shifting

#bang, #base, #column, #from, #result, #run_save, #shift_all_wrapper, #shift_each_wrapper, #to

Instance Method Summary collapse

Methods inherited from Shifting

#initialize

Constructor Details

This class inherits a constructor from Shiftable::Shifting

Instance Method Details

#each(&block) ⇒ Object



12
13
14
# File 'lib/shiftable/shifting_relation.rb', line 12

def each(&block)
  result.each(&block)
end

#found?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/shiftable/shifting_relation.rb', line 8

def found?
  result.any?
end

#shiftObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shiftable/shifting_relation.rb', line 17

def shift
  return false unless found?

  each do |record|
    record.send("#{column}=", to.id)
  end
  @run_save = yield if block_given?
  return result unless run_save

  run_save!
  result
end