Module: KeteTrackableItems::WorkflowUtilities::ClassMethods
- Defined in:
- lib/kete_trackable_items/workflow_utilities.rb
Overview
mostly grabbed from trollied, would be nice if split into shared lib
Instance Method Summary collapse
- #set_up_workflow_named_scopes ⇒ Object
-
#shared_tracking_workflow_specs_as_string ⇒ Object
kete_trackable_items specific stuff starts.
- #workflow_event_names ⇒ Object
-
#workflow_events ⇒ Object
returns a Hash where keys are event name and values are event object.
Instance Method Details
#set_up_workflow_named_scopes ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/kete_trackable_items/workflow_utilities.rb', line 62 def set_up_workflow_named_scopes Proc.new { # create a named_scope for each of our declared states workflow_spec.state_names.each do |name| scope_name = "with_state_#{name}".to_sym named_scope scope_name, :conditions => { :workflow_state => name.to_s }, :order => 'updated_at DESC' end # workflow_in(state_name) named_scope :workflow_in, lambda { |*args| = args.last.is_a?(Hash) ? args.pop : Hash.new state = args.is_a?(Array) ? args.first : args if state == 'all' else { :conditions => { :workflow_state => state.to_s }.merge() } end } } end |
#shared_tracking_workflow_specs_as_string ⇒ Object
kete_trackable_items specific stuff starts
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kete_trackable_items/workflow_utilities.rb', line 34 def shared_tracking_workflow_specs_as_string ' state :on_shelf do event :unassign_location, :transitions_to => :unallocated event :display, :transitions_to => :displayed event :hold_out, :transitions_to => :held_out event :loan, :transitions_to => :on_loan_to_organization end state :displayed do event :hold_out, :transitions_to => :held_out event :loan, :transitions_to => :on_loan_to_organization event :queue_for_refiling, :transitions_to => :to_be_refiled end state :held_out do event :loan, :transitions_to => :on_loan_to_organization event :queue_for_refiling, :transitions_to => :to_be_refiled end state :on_loan_to_organization do event :display, :transitions_to => :displayed event :hold_out, :transitions_to => :held_out event :queue_for_refiling, :transitions_to => :to_be_refiled end ' end |
#workflow_event_names ⇒ Object
29 30 31 |
# File 'lib/kete_trackable_items/workflow_utilities.rb', line 29 def workflow_event_names workflow_events.keys end |
#workflow_events ⇒ Object
returns a Hash where keys are event name and values are event object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kete_trackable_items/workflow_utilities.rb', line 12 def workflow_events events = workflow_spec.states.values.collect &:events # skip blank values events = events.select { |e| e.present? } # flatten events_hash = Hash.new events.each do |v| v.each do |key,value| events_hash[key] = value end end events_hash end |