Last active
December 15, 2015 20:19
-
-
Save bogn/5318133 to your computer and use it in GitHub Desktop.
Approval Workflow on instance level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def approval_by(role) | |
singleton_class_with_workflow = class << self | |
approval = self.class.approval_transitions_for[role] | |
workflow do | |
(approval || []).each do |state_name, events| | |
state state_name do | |
events.each do |event_name| | |
event event_name, transitions_to: EVENT_RESULTS[event_name] | |
end | |
end | |
end | |
end | |
self | |
end | |
singleton_class_with_workflow.workflow_spec | |
end | |
approval_by(:administrator) | |
#NoMethodError: undefined method `approval_transitions_for' for Class:Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Essentially self.class is not the "regular" class but the the class of the singleton class. I need a class-level attribute inside the singleton class.