class Shapeshifter::ShiftChain

Attributes

shifters[R]

Public Class Methods

new(first) click to toggle source
# File lib/shapeshifter/shift_chain.rb, line 3
def initialize(first)
  @shifters = [first]
end

Public Instance Methods

chain(shifter) click to toggle source
# File lib/shapeshifter/shift_chain.rb, line 7
def chain(shifter)
  shifters << shifter
  self
end
revert(source_object, target_object) click to toggle source
# File lib/shapeshifter/shift_chain.rb, line 22
def revert(source_object, target_object)
  can_be_dupped = source_object.respond_to?(:dup)
  shifters.reverse.each do |shifter_class|
    so = can_be_dupped ? source_object.dup : source_object
    shifter = shifter_class.new(so)
    target_object = shifter.revert(target_object)
  end
  target_object
end
shift(source_object, target_object) click to toggle source
# File lib/shapeshifter/shift_chain.rb, line 12
def shift(source_object, target_object)
  can_be_dupped = source_object.respond_to?(:dup)
  shifters.each do |shifter_class|
    so = can_be_dupped ? source_object.dup : source_object
    shifter = shifter_class.new(so)
    target_object = shifter.shift(target_object)
  end
  target_object
end