Class: Reflections::Remapper

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

Defined Under Namespace

Classes: NotSameClass

Constant Summary collapse

REMAPPERS =
[]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ Remapper

Returns a new instance of Remapper.



6
7
8
9
# File 'lib/reflections/remapper.rb', line 6

def initialize(from, to)
  @from_obj = from
  @to_obj = to
end

Instance Attribute Details

#from_objObject (readonly)

Returns the value of attribute from_obj.



4
5
6
# File 'lib/reflections/remapper.rb', line 4

def from_obj
  @from_obj
end

#to_objObject (readonly)

Returns the value of attribute to_obj.



4
5
6
# File 'lib/reflections/remapper.rb', line 4

def to_obj
  @to_obj
end

Instance Method Details

#remap(options = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# 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