Sha256: 5929ef8564fb047b97ef14de51541d7697464aaa29b5f05634cab6dee8ba9868
Contents?: true
Size: 931 Bytes
Versions: 1
Compression:
Stored size: 931 Bytes
Contents
module Rack module EncodingGuard class Middleware attr_reader :app, :strategy def initialize(app, strategy = nil, options = {}) @app = app @strategy = resolve_strategy_object(strategy, options) end def call(env) strategy.process(env) do app.call(env) end end private def resolve_strategy_object(strategy, options) case strategy when nil then SanitizeStrategy.new(options) when Class then strategy.new(options) when String then strategy.constantize.new(options) when Symbol class_name = "#{strategy.to_s.camelize}Strategy" EncodingGuard.const_get(class_name).new(options) else unless strategy.respond_to?(:process) fail ArgumentError, "Invalid strategy: #{strategy.inspect}" end strategy end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-encoding_guard-0.1.2 | lib/rack/encoding_guard/middleware.rb |