Skip to content

Instantly share code, notes, and snippets.

@bogn
Last active December 15, 2015 20:19
Show Gist options
  • Save bogn/5318133 to your computer and use it in GitHub Desktop.
Save bogn/5318133 to your computer and use it in GitHub Desktop.
Approval Workflow on instance level
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
@bogn
Copy link
Author

bogn commented Apr 5, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment