Class: Dragonfly::RoutedEndpoint
- Defined in:
- lib/dragonfly/routed_endpoint.rb
Defined Under Namespace
Classes: NoRoutingParams
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, &block) ⇒ RoutedEndpoint
constructor
A new instance of RoutedEndpoint.
- #inspect ⇒ Object
Constructor Details
#initialize(app, &block) ⇒ RoutedEndpoint
Returns a new instance of RoutedEndpoint.
10 11 12 13 |
# File 'lib/dragonfly/routed_endpoint.rb', line 10 def initialize(app, &block) @app = app @block = block end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dragonfly/routed_endpoint.rb', line 15 def call(env) params = Utils.symbolize_keys Rack::Request.new(env).params value = @block.call(params.merge(routing_params(env)), @app, env) case value when nil then plain_response(404, "Not Found") when Job, Model::Attachment job = value.is_a?(Model::Attachment) ? value.job : value Response.new(job, env).to_response else Dragonfly.warn("can't handle return value from routed endpoint: #{value.inspect}") plain_response(500, "Server Error") end rescue Job::NoSHAGiven plain_response(400, "You need to give a SHA parameter") rescue Job::IncorrectSHA plain_response(400, "The SHA parameter you gave is incorrect") end |
#inspect ⇒ Object
33 34 35 |
# File 'lib/dragonfly/routed_endpoint.rb', line 33 def inspect "<#{self.class.name} for app #{@app.name.inspect} >" end |