Sha256: 92ac3b5aabed227601d632d019e770e4b0beb5df465549b5bbfba7b29850fb50

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

module Wizard
  module Controller
    extend ActiveSupport::Concern 
    
    include ::Wizard::Controller::Concerns::Steps
    include ::Wizard::Controller::Concerns::Paths
    
    included do
      # Set step variables
      before_filter :setup_wizard, only: [:new, :create, :edit, :update]
    end
    
    private
    
    def setup_wizard
      @step  = action_name.try(:to_sym)
      
      unless wizard_steps.include? @step
        @step = nil
        
        step_from_event unless step_from_state
        
        @step = wizard_steps.first unless @step
      end
      
      
      
      @previous_step = previous_step(@step)
      @next_step = action_name.try(:to_sym) == @step ? @step : next_step(@step)
    end
    
    def step_from_state
      return false unless wizard_step_per_state.is_a?(Hash)
       
      state = resource.try(:state).try(:to_sym)
      
      return false unless state
      
      wizard_step_per_state.each do |step,states|
        if states.include?(state)
          @step = step
          break
        end
      end
      
      return @step ? true : false    
    end
    
    # TODO: just for backward compatibility purposes 
    def step_from_event
      @step = resource.try(:event).try(:to_sym)
      
      if @step && (!self.respond_to?(:current_step_is_next_step_after_event) || current_step_is_next_step_after_event) 
        @step = next_step(@step)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
voluntary-0.7.1 lib/wizard.rb
voluntary-0.7.0 lib/wizard.rb
voluntary-0.6.0 lib/wizard.rb
voluntary-0.5.2 lib/wizard.rb
voluntary-0.5.1 lib/wizard.rb
voluntary-0.5.0 lib/wizard.rb
voluntary-0.4.0 lib/wizard.rb
voluntary-0.3.0 lib/wizard.rb