Sha256: 8c95926ccc990badb5b9dd8024fb2b1a18006814587dff34e80e5311555e0f33

Contents?: true

Size: 1.24 KB

Versions: 21

Compression:

Stored size: 1.24 KB

Contents

module Applicat::Mvc::Controller::TransitionActions
  extend ActiveSupport::Concern

  private
  
  def fire_event(event, pass_event_to_assignment = false)
    authorize! event, resource
    
    #if params[resource.class.name.underscore.to_sym]
    #  resource.trigger = params[resource.class.name.underscore.to_sym][:trigger]
    #end
    
    resource.send(event)
    
    if resource.errors.full_messages.any?
      redirect_to :back, alert: resource.errors.full_messages.join(',')
    else
      redirect_to :back, notice: I18n.t('general.form.successfully_updated')  
    end
  end
  
  module ClassMethods
    private
    
    def transition_actions(*actions)
      actions = actions.first.is_a?(Symbol) ? actions : actions.first
      
      actions.each do |action|  
        define_method action do
          alternative_transition = nil
         
          alternative_transition = send "before_#{action}" if self.respond_to?("before_#{action}")
          
          alternative_transition = alternative_transition.is_a?(Symbol) ? alternative_transition : nil
          
          fire_event(alternative_transition || action) and return
          
          send "after_#{action}" if self.respond_to?("after_#{action}")
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
voluntary-0.7.1 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.7.0 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.6.0 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.5.2 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.5.1 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.5.0 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.4.0 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.3.0 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.2.4 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.2.3 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.2.2 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.2.1 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.2.0 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.1.0 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.1.0.rc4 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.1.0.rc3 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.1.0.rc2 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.1.0.rc1 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.0.3 lib/applicat/mvc/controller/transition_actions.rb
voluntary-0.0.2 lib/applicat/mvc/controller/transition_actions.rb