Class: ChronicTree::Command::RemoveChildElementsFromAncestors

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, ancestor_ids, child_ids) ⇒ RemoveChildElementsFromAncestors

Returns a new instance of RemoveChildElementsFromAncestors.



56
57
58
59
60
# File 'lib/chronic_tree/command.rb', line 56

def initialize(source, ancestor_ids, child_ids)
  @source = source
  @ancestor_ids = ancestor_ids
  @child_ids = child_ids
end

Instance Attribute Details

#ancestor_idsObject (readonly)

Returns the value of attribute ancestor_ids.



54
55
56
# File 'lib/chronic_tree/command.rb', line 54

def ancestor_ids
  @ancestor_ids
end

#child_idsObject (readonly)

Returns the value of attribute child_ids.



54
55
56
# File 'lib/chronic_tree/command.rb', line 54

def child_ids
  @child_ids
end

#sourceObject (readonly)

Returns the value of attribute source.



54
55
56
# File 'lib/chronic_tree/command.rb', line 54

def source
  @source
end

Instance Method Details

#doObject



62
63
64
65
66
67
68
69
# File 'lib/chronic_tree/command.rb', line 62

def do
  ChronicTree::ActiveRecord::Element.at(source.current_time_at).
    where(tree_type: source.class.name).
    where(scope_name: source.current_scope_name).
    where(parent_id: ancestor_ids).
    where(child_id: child_ids).
    update_all(end_time: source.current_time_at)
end