Module: ChronicTree

Includes:
ActiveRecord::Relation, Operation, Travesal
Defined in:
lib/chronic_tree.rb,
lib/chronic_tree/command.rb,
lib/chronic_tree/railtie.rb,
lib/chronic_tree/version.rb,
lib/chronic_tree/travesal.rb,
lib/chronic_tree/operation.rb,
lib/chronic_tree/active_record/element.rb,
lib/chronic_tree/active_record/relation.rb,
lib/generators/chronic_tree/install_generator.rb

Defined Under Namespace

Modules: ActiveRecord, ClassMethods, Command, Operation, Travesal Classes: Error, InstallGenerator, InvalidObjectError, Railtie

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Operation

#add_as_root, #add_child, #change_parent, #remove_descendants, #remove_self, #replace_by

Methods included from Travesal

#ancestors, #children, #descendants, #existed_in_tree?, #flat_descendants, #parent, #root, #tree_empty?

Methods included from ActiveRecord::Relation

#ancestors_relation, #children_relation, #descendants_relation, #existed_relation, #parent_relation

Class Method Details

.included(base) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chronic_tree.rb', line 18

def self.included(base)
  base.class_eval <<-RUBY
    attr_reader :current_time_at, :current_scope_name

    @@defined_chronic_tree_scopes = Set.new

    def self.defined_chronic_tree_scopes
      @@defined_chronic_tree_scopes
    end
  RUBY

  base.extend(ClassMethods)
end

Instance Method Details

#as_tree(time_at = Time.now, scope_name = 'default') ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/chronic_tree.rb', line 60

def as_tree(time_at = Time.now, scope_name = 'default')
  time_at, scope_name = Time.now, time_at if time_at.is_a?(String)

  raise "Scope name is wrong.  It should be equal to the name that has " \
   "been set up." unless self.class.defined_chronic_tree_scopes.include?(scope_name)

  raise "Time can't be later than now." if time_at > Time.now

  @current_time_at = time_at
  @current_scope_name = scope_name

  self
end