Skip to content

Instantly share code, notes, and snippets.

@kinsteronline
Created May 16, 2012 20:34
Show Gist options
  • Save kinsteronline/2713730 to your computer and use it in GitHub Desktop.
Save kinsteronline/2713730 to your computer and use it in GitHub Desktop.
Authorization states in a Proc
class Customer < AR::Base
authorization_states = Proc.new do
event :start_authorizing do
transition all => :authorizing
end
event :finish_authorizing do
transition :authorizing => :authorized
end
event :fail_to_authorize do
transition [:authorizing, :unauthorized] => :auth_failure
end
event :deauthorize do
transition all => :unauthorized
end
end
state_machine :facebook_auth_state, {
:initial => :unauthorized,
:namespace => 'facebook'
}, &authorization_states
state_machine :twitter_auth_state, {
:initial => :unauthorized,
:namespace => 'twitter'
}, &authorization_states
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment