module ActiveWorker::Behavior::ActsAsRootObject
Public Class Methods
included(base)
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 14 def self.included(base) base.extend(ClassExtensions) base.send(:include, Mongoid::Timestamps) base.field :root_object_finished, :type => Boolean, :default => false base.field :finished_at, :type => Time base.field :flags, :type => Hash, :default => {} base.before_save :set_flags base.acts_as_root_for :configurations, "ActiveWorker::Configuration" base.acts_as_root_for :events, "ActiveWorker::Event" end
Public Instance Methods
all_configuration_hashes()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 69 def all_configuration_hashes @renderable_configurations_hash ||= ActiveWorker::Configuration.get_as_flat_hash_by_root_object(self) end
calculate_completed()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 49 def calculate_completed immediate_child_configurations.each do |config| return false unless config.completed? end self.finished_at = Time.now true end
child_finished()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 45 def child_finished self.root_object_finished = calculate_completed end
child_started()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 41 def child_started self.root_object_finished = false end
completed?()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 37 def completed? self.root_object_finished end
duration()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 25 def duration if completed? && finished_at return finished_at - created_at end if completed? && !finished_at return 0 end Time.now - created_at end
immediate_child_configurations()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 61 def immediate_child_configurations configurations.where(parent_configuration_id: nil) end
renderable_configuration_hashes()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 65 def renderable_configuration_hashes @renderable_configurations_hash ||= ActiveWorker::Configuration.get_renderable_hash_by_root_object(self) end
renderable_configurations()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 57 def renderable_configurations immediate_child_configurations.select { |c| c.renderable } end
set_flags()
click to toggle source
# File lib/active_worker/behavior/acts_as_root_object.rb, line 73 def set_flags immediate_child_configurations.each do |config| config.update_attributes(:flags => flags) end end