Class: ChronicTree::Operation::ReplaceBy

Inherits:
Object
  • Object
show all
Defined in:
lib/chronic_tree/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_elementsObject (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

#sourceObject (readonly)

Returns the value of attribute source.



45
46
47
# File 'lib/chronic_tree/operation.rb', line 45

def source
  @source
end

#source_ancestorsObject (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_idObject (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

#targetObject (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

#actObject



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