mirror of
				https://github.com/aasm/aasm
				synced 2023-03-27 23:22:41 -04:00 
			
		
		
		
	deprecate usage of AASM.aasm_initial_state (getter and setter method)
This commit is contained in:
		
							parent
							
								
									45250d09e2
								
							
						
					
					
						commit
						c5ae69ca64
					
				
					 6 changed files with 13 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -26,12 +26,13 @@ module AASM
 | 
			
		|||
      @aasm
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # TODO: maybe better: aasm.initial_state
 | 
			
		||||
    # TODO remove this method in v4.0.0
 | 
			
		||||
    def aasm_initial_state(set_state=nil)
 | 
			
		||||
      if set_state
 | 
			
		||||
        # deprecated way to set the value
 | 
			
		||||
        warn ".aasm_initial_state(:name) is deprecated and will be removed in version 4.0.0; please use .aasm.initial_state = :name instead!"
 | 
			
		||||
        AASM::StateMachine[self].initial_state = set_state
 | 
			
		||||
      else
 | 
			
		||||
        warn ".aasm_initial_state is deprecated and will be removed in version 4.0.0; please use .aasm.initial_state instead!"
 | 
			
		||||
        AASM::StateMachine[self].initial_state
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,13 +25,16 @@ module AASM
 | 
			
		|||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def initial_state
 | 
			
		||||
      @state_machine.initial_state
 | 
			
		||||
    def initial_state(new_initial_state=nil)
 | 
			
		||||
      if new_initial_state
 | 
			
		||||
        @state_machine.initial_state = new_initial_state
 | 
			
		||||
      else
 | 
			
		||||
        @state_machine.initial_state
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # define a state
 | 
			
		||||
    def state(name, options={})
 | 
			
		||||
      # @clazz.aasm_state(name, options)
 | 
			
		||||
      @state_machine.add_state(name, @clazz, options)
 | 
			
		||||
      @state_machine.initial_state = name if options[:initial] || !@state_machine.initial_state
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ module AASM
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    def enter_initial_state
 | 
			
		||||
      state_name = determine_state_name(@instance.class.aasm_initial_state)
 | 
			
		||||
      state_name = determine_state_name(@instance.class.aasm.initial_state)
 | 
			
		||||
      state_object = state_object_for_name(state_name)
 | 
			
		||||
 | 
			
		||||
      state_object.fire_callbacks(:before_enter, @instance)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,7 +35,7 @@ module AASM
 | 
			
		|||
      def aasm_read_state
 | 
			
		||||
        state = send(self.class.aasm_column)
 | 
			
		||||
        if new_record?
 | 
			
		||||
          state.blank? ? aasm.determine_state_name(self.class.aasm_initial_state) : state.to_sym
 | 
			
		||||
          state.blank? ? aasm.determine_state_name(self.class.aasm.initial_state) : state.to_sym
 | 
			
		||||
        else
 | 
			
		||||
          state.nil? ? nil : state.to_sym
 | 
			
		||||
        end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,10 +62,10 @@ class Thief < ActiveRecord::Base
 | 
			
		|||
    set_table_name "thieves"
 | 
			
		||||
  end
 | 
			
		||||
  include AASM
 | 
			
		||||
  aasm_initial_state  Proc.new { |thief| thief.skilled ? :rich : :jailed }
 | 
			
		||||
  aasm do
 | 
			
		||||
    state :rich
 | 
			
		||||
    state :jailed
 | 
			
		||||
    initial_state Proc.new {|thief| thief.skilled ? :rich : :jailed }
 | 
			
		||||
  end
 | 
			
		||||
  attr_accessor :skilled, :aasm_state
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,8 @@ class Banker
 | 
			
		|||
  aasm do
 | 
			
		||||
    state :retired
 | 
			
		||||
    state :selling_bad_mortgages
 | 
			
		||||
    initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
 | 
			
		||||
  end
 | 
			
		||||
  aasm_initial_state  Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
 | 
			
		||||
  RICH = 1_000_000
 | 
			
		||||
  attr_accessor :balance
 | 
			
		||||
  def initialize(balance = 0); self.balance = balance; end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue