class Reflections::Remapper
Constants
- REMAPPERS
Attributes
from_obj[R]
to_obj[R]
Public Class Methods
new(from, to)
click to toggle source
# File lib/reflections/remapper.rb, line 6 def initialize(from, to) @from_obj = from @to_obj = to end
Public Instance Methods
remap(options={}, &block)
click to toggle source
# File lib/reflections/remapper.rb, line 11 def remap(options={}, &block) protect_remap_from_other_classes @only_these_classes = options.fetch(:only) { ActiveRecord::Base.descendants } @except_these_classes = options.fetch(:except) { [] } remap_these = options.fetch(:types) { REMAPPERS } remap_these.each do |remapper| remapper_class = "Reflections::Remappers::#{remapper.to_s.camelize}".constantize remapper_class.new(from_obj, to_obj).remap(ar_classes, &block) end end
Protected Instance Methods
ar_classes()
click to toggle source
# File lib/reflections/remapper.rb, line 24 def ar_classes @only_these_classes - @except_these_classes end
Private Instance Methods
associations_for_class(ar_class)
click to toggle source
# File lib/reflections/remapper.rb, line 42 def associations_for_class(ar_class) filter = filter_for_class from_obj.class associations(ar_class).select &filter end
protect_remap_from_other_classes()
click to toggle source
# File lib/reflections/remapper.rb, line 30 def protect_remap_from_other_classes if from_obj.class != to_obj.class raise NotSameClass, "#{from_obj.class} is not the same class as #{to_obj.class}" end end
update_record_or_yield(record, association) { |record, from_obj, to_obj| ... }
click to toggle source
# File lib/reflections/remapper.rb, line 36 def update_record_or_yield(record, association) if !block_given? || block_given? && yield(record, from_obj, to_obj) update_record record, association end end