Module: StonePath::SPTask

Defined in:
lib/stonepath/task.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_config_blockObject

This will move from here shortly, into another class/module for containing things like this. This is the workflow definition for a default task. This is defined this way so that users can provide their own task workflow definition as a block to the stonepath_task declaration. This lanbda is passed in if the user doesn’t provide anything. It is possible that we will identify other useful options and want to provide them as config blocks in the StonePath gem.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/stonepath/task.rb', line 14

def self.default_config_block
  lambda {
    aasm_initial_state :active
    aasm_state :active, :after_enter => :notify_created
    aasm_state :completed, :enter => :timestamp_complete, :after_enter => :notify_closed
    # was:
    #aasm_state :completed, :after_enter => [:timestamp_complete, :notify_closed]
    # but, from investigations into AASM,
    # persist is done after :enter but before :after_exit, etc
    # so fields changed in :after_enter will result in a dirty object that
    # never gets saved to the DB
    # WD-rpw / Ashish Tonse 11-16-2010

    aasm_state :expired, :after_enter => :notify_closed
    aasm_state :cancelled, :after_enter => :notify_closed

    aasm_event :complete do
      transitions :to => :completed, :from => :active
    end

    aasm_event :cancel do
      transitions :to => :cancelled, :from => [:active, :completed]
    end

    aasm_event :expire do
      transitions :to => :expired, :from => :active
    end

    named_scope :unassigned, { :conditions => ['workbench_id IS NULL'] }
    named_scope :assigned, { :conditions => ['workbench_id IS NOT NULL'] }
    named_scope :active, { :conditions => ['aasm_state in (?)', ['active']] }
    named_scope :completed, { :conditions => ['aasm_state in (?)', ['completed']] }
    named_scope :expired, { :conditions => ['aasm_state in (?)', ['expired']] }
    named_scope :cancelled, { :conditions => ['aasm_state in (?)', ['cancelled']] }
    named_scope :overdue, lambda { { :conditions => ['aasm_state in (?) AND due_at < ?',  ['active'], Time.now] } }
  }
end

.included(base) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/stonepath/task.rb', line 53

def self.included(base)
  base.instance_eval do
    include AASM
  
    # Tasks are now completely polymorphic between workbenches.
    # as long as an activerecord model declares itself as a workbench and declares itself
    # a workbench for the specific kind of task, everything just works.
    belongs_to :workbench, :polymorphic => true
    
    # Tasks are now completely polymorphic between workitems.
    # as long as an activerecord model declares itself as a workitem and declares itself
    # a workitem for the specific kind of task, everything just works.
    belongs_to :workitem, :polymorphic => true
    
    #add the ability to log events if the user so specifies
    require File.expand_path(File.dirname(__FILE__)) + "/event_logging.rb"
    extend StonePath::EventLogging
    
    require File.expand_path(File.dirname(__FILE__)) + "/dot.rb"
    extend StonePath::Dot
    
  end
end

Instance Method Details

#overdue?Boolean

I don’t think this should really be part of Stonepath, but I’m adding it here as a comment to communicate some design intent to my fellow teammembers on a project using stonepath. For the ‘timely|imminent|overdue’ stuff, at the time the task is created, we would need to set and calculate the imminent_at and due_at times. These methods would then do what we need them to do. def imminent?

return false if imminent_at.nil?
imminent_at < Time.now

end

we might also want this method, which would be useful in css styling def timeliness

return "overdue" if overdue?
return "imminent" if imminent?
return "timely"

end

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/stonepath/task.rb', line 94

def overdue?
  return false if due_at.nil?
  due_at < Time.now  
end