Sha256: 362775c81f40027d289609cd010ea0d3cb56efcb4d14d769a96c01b9978d5dd5

Contents?: true

Size: 1.16 KB

Versions: 47

Compression:

Stored size: 1.16 KB

Contents

module Dragonfly
  class RoutedEndpoint

    class NoRoutingParams < RuntimeError; end

    def initialize(app, &block)
      @app = app
      @block = block
    end

    def call(env)
      params = symbolize_keys_of Rack::Request.new(env).params
      job = @block.call(params.merge(routing_params(env)), @app)
      Response.new(job, env).to_response
    rescue Job::NoSHAGiven => e
      [400, {"Content-Type" => 'text/plain'}, ["You need to give a SHA parameter"]]
    rescue Job::IncorrectSHA => e
      [400, {"Content-Type" => 'text/plain'}, ["The SHA parameter you gave (#{e}) is incorrect"]]
    end

    def inspect
      "<#{self.class.name} for app #{@app.name.inspect} >"
    end

    private

    def routing_params(env)
      env['rack.routing_args'] ||
        env['action_dispatch.request.path_parameters'] ||
        env['router.params'] ||
        env['usher.params'] ||
        env['dragonfly.params'] ||
        raise(NoRoutingParams, "couldn't find any routing parameters in env #{env.inspect}")
    end

    def symbolize_keys_of(hash)
      hash.inject({}) do |h, (key, value)|
        h[(key.to_sym rescue key) || key] = value
        h
      end
    end

  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.7.4 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.7.3 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.7.2 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.7.1 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.7.0 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.9 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.8 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.7 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.6 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.5 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.4 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.3 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.2 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.1 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.6.0 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.5.17 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.5.16 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.5.15 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb
classiccms-0.5.14 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/routed_endpoint.rb