Class: ChronicTree::Operation::ReplaceBy
- Inherits:
-
Object
- Object
- ChronicTree::Operation::ReplaceBy
- Defined in:
- lib/chronic_tree/operation.rb
Instance Attribute Summary collapse
-
#ready_to_move_elements ⇒ Object
readonly
Returns the value of attribute ready_to_move_elements.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#source_ancestors ⇒ Object
readonly
Returns the value of attribute source_ancestors.
-
#source_root_id ⇒ Object
readonly
Returns the value of attribute source_root_id.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #act ⇒ Object
-
#initialize(source, target) ⇒ ReplaceBy
constructor
A new instance of ReplaceBy.
Constructor Details
#initialize(source, target) ⇒ ReplaceBy
Returns a new instance of ReplaceBy.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chronic_tree/operation.rb', line 47 def initialize(source, target) @source = source @target = target @ready_to_move_elements = source.descendants_relation( source.current_time_at, source.current_scope_name).map do |el| OpenStruct.new(id: el.id, child_id: el.child_id, distance: el.distance) end @source_root_id = (source == source.root) ? target.id : source.root.id @source_ancestors = source.ancestors end |
Instance Attribute Details
#ready_to_move_elements ⇒ Object (readonly)
Returns the value of attribute ready_to_move_elements.
45 46 47 |
# File 'lib/chronic_tree/operation.rb', line 45 def ready_to_move_elements @ready_to_move_elements end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
45 46 47 |
# File 'lib/chronic_tree/operation.rb', line 45 def source @source end |
#source_ancestors ⇒ Object (readonly)
Returns the value of attribute source_ancestors.
45 46 47 |
# File 'lib/chronic_tree/operation.rb', line 45 def source_ancestors @source_ancestors end |
#source_root_id ⇒ Object (readonly)
Returns the value of attribute source_root_id.
45 46 47 |
# File 'lib/chronic_tree/operation.rb', line 45 def source_root_id @source_root_id end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
45 46 47 |
# File 'lib/chronic_tree/operation.rb', line 45 def target @target end |
Instance Method Details
#act ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/chronic_tree/operation.rb', line 62 def act ::ActiveRecord::Base.transaction do remove_obsolete_elements add_new_elements end source end |