Skip to content

Instantly share code, notes, and snippets.

@bentona
Created April 22, 2016 21:22
Show Gist options
  • Save bentona/07fce1bdabb8d3856aa852ef2744ad8b to your computer and use it in GitHub Desktop.
Save bentona/07fce1bdabb8d3856aa852ef2744ad8b to your computer and use it in GitHub Desktop.
class FunnelStrategy < ActiveRecord::Base
belongs_to :organization
STATES = State.new [
:company_information,
:strategy_information,
:account_information,
:landing_page,
:email_1,
:email_2,
:email_3,
:email_4,
:complete
]
def current_state
state
end
def transition_to_next
transition_to = next_state
return false unless transition_to
update(state: transition_to)
end
private
def next_state
STATES[state].next.try(:name)
end
end
class State
attr_accessor :next, :name
def initialize(name, next_states = [])
@name = name
if next_states.first
@next = State.new(next_states.first, next_states[1..-1])
end
end
def [] index
return self if name == index
return @next && @next[index]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment