Module: StonePath::WorkItem

Defined in:
lib/stonepath/work_item.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
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
# File 'lib/stonepath/work_item.rb', line 7

def self.included(base)
  base.instance_eval do
    include AASM
    
    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
    
    def owned_by(owner, options={})
      options.merge!(:class_name => owner.to_s.classify)
      belongs_to :owner, options
    end
    
    def tasked_through(tasks, options={})
      options.merge!(:as => :workitem)
      has_many tasks, options
    end
    
  end #base.instance_eval
  
  # modifies to_xml do that it includes all the possible events from this state.
  # useful when you are using WorkItems as resources with ActiveResource
  def to_xml_with_events
    to_xml_without_events do |xml|
      xml.aasm_events_for_current_state(:type=>"array") do
        aasm_events_for_current_state.each do |e|
          xml.aasm_event do
            xml.name e.to_s
          end
        end
      end
    end
  end
  
  base.instance_eval do
    unless method_defined? :to_xml_without_events
      alias_method_chain :to_xml, :events
    end
  end
  
end

Instance Method Details

#to_xml_with_eventsObject

modifies to_xml do that it includes all the possible events from this state. useful when you are using WorkItems as resources with ActiveResource



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stonepath/work_item.rb', line 31

def to_xml_with_events
  to_xml_without_events do |xml|
    xml.aasm_events_for_current_state(:type=>"array") do
      aasm_events_for_current_state.each do |e|
        xml.aasm_event do
          xml.name e.to_s
        end
      end
    end
  end
end