Class: ChronicTree::Command::AddChildElement

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, child_object_or_child_id, distance = 1, source_root_id = nil) ⇒ AddChildElement

Returns a new instance of AddChildElement.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chronic_tree/command.rb', line 25

def initialize(source, child_object_or_child_id, distance = 1, source_root_id = nil)
  @source = source
  @source_root_id = if source_root_id.nil?
    source.root.id
  else
    source_root_id
  end

  @distance = distance

  @child_id = if child_object_or_child_id.respond_to?(:id)
    child_object_or_child_id.send(:id)
  else
    child_object_or_child_id
  end
end

Instance Attribute Details

#child_idObject (readonly)

Returns the value of attribute child_id.



23
24
25
# File 'lib/chronic_tree/command.rb', line 23

def child_id
  @child_id
end

#distanceObject (readonly)

Returns the value of attribute distance.



23
24
25
# File 'lib/chronic_tree/command.rb', line 23

def distance
  @distance
end

#sourceObject (readonly)

Returns the value of attribute source.



23
24
25
# File 'lib/chronic_tree/command.rb', line 23

def source
  @source
end

#source_root_idObject (readonly)

Returns the value of attribute source_root_id.



23
24
25
# File 'lib/chronic_tree/command.rb', line 23

def source_root_id
  @source_root_id
end

Instance Method Details

#doObject



42
43
44
45
46
47
48
49
50
# File 'lib/chronic_tree/command.rb', line 42

def do
  source.send("elements_under_#{source.current_scope_name}_parent").create(
    root_id: source_root_id,
    child_id: child_id,
    distance: distance,
    start_time: source.current_time_at,
    end_time: 1000.years.since(source.current_time_at)
  )
end