Sha256: 145dec39e2b0ede8efe0ace6519ba85c4c6da9a049c022a7c85916df57def0e9

Contents?: true

Size: 1006 Bytes

Versions: 3

Compression:

Stored size: 1006 Bytes

Contents

module Controll::Enabler
  class PathHandler
    attr_reader :controller, :type, :options, :path

    def initialize controller, type
      @controller, @type = [controller, type]
    end

    def self.renderer controller, map
      self.new controller, map, :render
    end

    def self.redirecter controller, map
      self.new controller, map, :redirect
    end

    def execute *args
      extract! *args
      process_notifications
      path ? handle_path : fallback
    end

    protected

    def map
      @map ||= controller.class.send("#{type}_map") 
    end

    alias_method :control_action, :type

    def handle_path
      controller.send control_action, path, options
    end

    def fallback
      controller.do_fallback action
    end

    def extract! *args
      @options = args.extract_options!
      action = args.first
      @path = path_resolver(map).resolve action
    end

    def path_resolver map
      @path_resolver ||= PathResolver.new controller, map
    end    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
controll-0.3.2 lib/controll/enabler/path_handler.rb
controll-0.3.1 lib/controll/enabler/path_handler.rb
controll-0.3.0 lib/controll/enabler/path_handler.rb