Module: StateMachines::Vacancy
- Included in:
- Vacancy
- Defined in:
- app/models/state_machines/vacancy.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/state_machines/vacancy.rb', line 2 def self.included(base) base.extend ClassMethods base.class_eval do attr_accessor :current_user const_set 'STATES', [:open, :recommended, :denied, :closed] const_set 'EVENTS', [:accept_recommendation, :deny_recommendation, :close, :reopen] after_initialize :set_initial_state state_machine :state, initial: :new do event :recommend do transition :new => :recommended end event :accept_recommendation do transition :recommended => :open end event :deny_recommendation do transition :recommended => :denied end event :do_open do transition :new => :open end event :close do transition :open => :closed end event :reopen do transition [:denied, :closed] => :open end end private def set_initial_state self.state ||= :new end end end |