class Shiftable::Shifting
Gets data to be shifted
Attributes
bang[RW]
Public API
base[R]
Internal API
column[R]
Internal API
from[R]
result[RW]
Public API
run_save[R]
Internal API
shift_all_wrapper[RW]
Public API
shift_each_wrapper[RW]
Public API
to[R]
Public Class Methods
new(to:, from:, column:, base:, wrapper:, bang:) { |: true| ... }
click to toggle source
# File lib/shiftable/shifting.rb, line 12 def initialize(to:, from:, column:, base:, wrapper:, bang:) @to = to @from = from @column = column @base = base validate do_query = block_given? ? yield : true @result = do_query ? query : nil @run_save = true @shift_all_wrapper = wrapper[:all] @shift_each_wrapper = wrapper[:each] @bang = bang end
Private Instance Methods
do_saves()
click to toggle source
# File lib/shiftable/shifting.rb, line 51 def do_saves if shift_each_wrapper each do |rec| shift_each_wrapper.call(self, rec) do bang ? rec.save! : rec.save end end else bang ? each(&:save!) : each(&:save) end end
run_save!()
click to toggle source
# File lib/shiftable/shifting.rb, line 41 def run_save! if shift_all_wrapper shift_all_wrapper.call(self) do do_saves end else do_saves end end
validate()
click to toggle source
def shift
raise "shift must be defined in a subclass"
end
# File lib/shiftable/shifting.rb, line 36 def validate raise ArgumentError, "shift_to must have an id (primary key) value, but is: #{to&.id}" unless to&.id raise ArgumentError, "shift_from must have an id (primary key) value, but is: #{from&.id}" unless from&.id end