Sha256: bac9c003c36793e038684205fcd168c06705269971de965223434cf8319b46e6

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module Volt
  class ControllerHandler
    attr_reader :controller, :action

    def initialize(controller, action)
      @controller = controller
      @action = action.to_sym
    end

    def call_action(stage_prefix=nil, stage_suffix=nil)
      return unless @action

      has_stage = stage_prefix || stage_suffix

      if has_stage
        method_name = @action
        method_name = "#{stage_prefix}_#{method_name}" if stage_prefix
        method_name = "#{method_name}_#{stage_suffix}" if stage_suffix

        method_name = method_name.to_sym
      else
        method_name = @action
      end

      # If no stage, then we are calling the main action method,
      # so we should call the before/after actions
      unless has_stage
        if @controller.run_actions(:before, @action)
          # stop_chain was called
          return true
        end
      end

      if @controller.respond_to?(method_name)
        @controller.send(method_name)
      end

      @controller.run_actions(:after, @action) unless has_stage

      # before_action chain was not stopped
      return false
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
volt-0.9.0.pre7 lib/volt/page/bindings/view_binding/controller_handler.rb
volt-0.9.0.pre6 lib/volt/page/bindings/view_binding/controller_handler.rb
volt-0.9.0.pre5 lib/volt/page/bindings/view_binding/controller_handler.rb