Class: Reflections::Remapper
- Inherits:
-
Object
- Object
- Reflections::Remapper
- Defined in:
- lib/reflections/remapper.rb
Direct Known Subclasses
Reflections::Remappers::BelongsTo, Reflections::Remappers::HasAndBelongsToMany
Defined Under Namespace
Classes: NotSameClass
Constant Summary collapse
- REMAPPERS =
[]
Instance Attribute Summary collapse
-
#from_obj ⇒ Object
readonly
Returns the value of attribute from_obj.
-
#to_obj ⇒ Object
readonly
Returns the value of attribute to_obj.
Instance Method Summary collapse
-
#initialize(from, to) ⇒ Remapper
constructor
A new instance of Remapper.
- #remap(options = {}, &block) ⇒ Object
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_obj ⇒ Object (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_obj ⇒ Object (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(={}, &block) protect_remap_from_other_classes @only_these_classes = .fetch(:only) { ActiveRecord::Base.descendants } @except_these_classes = .fetch(:except) { [] } remap_these = .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 |