Class: ChronicTree::Command::AddChildElement
- Inherits:
-
Object
- Object
- ChronicTree::Command::AddChildElement
- Defined in:
- lib/chronic_tree/command.rb
Instance Attribute Summary collapse
-
#child_id ⇒ Object
readonly
Returns the value of attribute child_id.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#source_root_id ⇒ Object
readonly
Returns the value of attribute source_root_id.
Instance Method Summary collapse
- #do ⇒ Object
-
#initialize(source, child_object_or_child_id, distance = 1, source_root_id = nil) ⇒ AddChildElement
constructor
A new instance of AddChildElement.
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_id ⇒ Object (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 |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
23 24 25 |
# File 'lib/chronic_tree/command.rb', line 23 def distance @distance end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
23 24 25 |
# File 'lib/chronic_tree/command.rb', line 23 def source @source end |
#source_root_id ⇒ Object (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
#do ⇒ Object
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 |