Sha256: bb49e12b1f53b6f06fcc655e061773265b05d572d4314c9fec95f92dcee24850

Contents?: true

Size: 869 Bytes

Versions: 13

Compression:

Stored size: 869 Bytes

Contents

class Rack::Tracker::HandlerDelegator
  class << self
    def handler(method_name)
      new.handler(method_name)
    end
  end

  attr_accessor :env

  def initialize(env = {})
    @env = env
  end

  def method_missing(method_name, *args, &block)
    if respond_to?(method_name)
      handler(method_name).process_track(env, method_name, *args, &block)
    else
      super
    end
  end

  def respond_to?(method_name, include_private = false)
    handler(method_name).respond_to?(:track, include_private)
  end

  def handler(method_name)
    return method_name if method_name.kind_of?(Class)

    _handler = method_name.to_s.camelize
    ["Rack::Tracker::#{_handler}", _handler].detect do |const|
      begin
        return const.constantize
      rescue NameError
        false
      end
    end

    raise ArgumentError, "No such Handler: #{_handler}"
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rack-tracker-1.13.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.12.1 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.12.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.11.2 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.11.1 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.11.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.10.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.9.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.8.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.7.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.6.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.5.0 lib/rack/tracker/handler_delegator.rb
rack-tracker-1.4.0 lib/rack/tracker/handler_delegator.rb