have workflow add its methods through a module

this allows another module included later in the model to define
similarly named methods and have them take precedence over (and also be
able to use via super) the ones defined by workflow.

Change-Id: Ib4fb472c1a1fc90e571fb3f006f0eccb29e96fcc
Reviewed-on: https://gerrit.instructure.com/43976
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Jacob Fugal <jacob@instructure.com>
Product-Review: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
Jacob Fugal 2014-11-05 15:58:18 -07:00
parent c91836e9fa
commit 71d91e92ab
1 changed files with 5 additions and 2 deletions

View File

@ -112,10 +112,11 @@ module Workflow
end
def workflow(&specification)
workflow_methods = Module.new
self.workflow_spec = Specification.new(Hash.new, &specification)
self.workflow_spec.states.values.each do |state|
state_name = state.name
module_eval do
workflow_methods.module_eval do
define_method "#{state_name}?" do
state_name == current_state.name
end
@ -123,7 +124,7 @@ module Workflow
state.events.values.each do |event|
event_name = event.name
module_eval do
workflow_methods.module_eval do
define_method "#{event_name}!".to_sym do |*args|
process_event!(event_name, *args)
end
@ -134,6 +135,8 @@ module Workflow
end
end
end
include workflow_methods
end
end