class Slimer::WebAction
Everything needed for handling an HTTP request Borrowed from Sidekiq:
https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/web/action.rb
Constants
- RACK_SESSION
Attributes
block[RW]
env[RW]
type[RW]
Public Class Methods
new(env, block)
click to toggle source
# File lib/slimer/web/action.rb, line 62 def initialize(env, block) @env = env @block = block @files ||= {} end
Public Instance Methods
forbidden()
click to toggle source
# File lib/slimer/web/action.rb, line 28 def forbidden throw :halt, [403, { "Content-Type" => "text/plain" }, ["Forbidden"]] end
halt(res)
click to toggle source
# File lib/slimer/web/action.rb, line 20 def halt(res) throw :halt, res end
json(payload)
click to toggle source
# File lib/slimer/web/action.rb, line 58 def json(payload) [200, { "Content-Type" => "application/json", "Cache-Control" => "no-cache" }, [JSON.generate(payload)]] end
params()
click to toggle source
# File lib/slimer/web/action.rb, line 41 def params indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key } # rubocop:disable Style/CaseEquality indifferent_hash.merge! request.params route_params.each { |k, v| indifferent_hash[k.to_s] = v } indifferent_hash end
redirect(location)
click to toggle source
# File lib/slimer/web/action.rb, line 24 def redirect(location) throw :halt, [302, { "Location" => "#{request.base_url}#{location}" }, []] end
request()
click to toggle source
# File lib/slimer/web/action.rb, line 16 def request @request ||= ::Rack::Request.new(env) end
route_params()
click to toggle source
# File lib/slimer/web/action.rb, line 50 def route_params env[WebRouter::ROUTE_PARAMS] end
session()
click to toggle source
# File lib/slimer/web/action.rb, line 54 def session env[RACK_SESSION] end
settings()
click to toggle source
# File lib/slimer/web/action.rb, line 12 def settings Web.settings end