Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created March 3, 2011 12:31
Show Gist options
  • Save JakubOboza/852695 to your computer and use it in GitHub Desktop.
Save JakubOboza/852695 to your computer and use it in GitHub Desktop.
aasm
require 'rubygems'
require 'aasm'
# show me the caller name
module Wombatize
def method_name
caller[0][/`([^']*)'/, 1]
end
end
class Relationship
# add aasm
include AASM
include Wombatize
#aasm_column :status
#above fails on Ruby [1.8.7-p299, 1.8.7-p302, 1.9.2-p0] OSX 10.6.6
aasm_initial_state Proc.new { |relationship| relationship.strictly_for_fun? ? :intimate : :dating }
aasm_state :dating, :enter => :make_happy, :exit => :make_depressed
aasm_state :intimate, :enter => :make_very_happy, :exit => :never_speak_again
aasm_state :married, :enter => :give_up_intimacy, :exit => :buy_exotic_car_and_wear_a_combover
aasm_event :get_intimate do
transitions :to => :intimate, :from => [:dating], :guard => :drunk?
end
aasm_event :get_married do
transitions :to => :married, :from => [:dating, :intimate], :guard => :willing_to_give_up_manhood?
end
def strictly_for_fun?
puts method_name
end
def drunk?
puts method_name
end
def willing_to_give_up_manhood?
puts method_name
end
def make_happy
puts method_name
end
def make_depressed
puts method_name
end
def make_very_happy
puts method_name
end
def never_speak_again
puts method_name
end
def give_up_intimacy
puts method_name
end
def buy_exotic_car_and_wear_a_combover
puts method_name
end
end
r = Relationship.new
r.get_married
r.get_married
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment