Class: RecurringSelectMiddleware

Inherits:
Object
  • Object
show all
Defined in:
app/middleware/recurring_select_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RecurringSelectMiddleware

Returns a new instance of RecurringSelectMiddleware.


5
6
7
# File 'app/middleware/recurring_select_middleware.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/middleware/recurring_select_middleware.rb', line 9

def call(env)
  regexp = /^\/recurring_select\/translate\/(.*)/
  if env["PATH_INFO"] =~ regexp
    I18n.locale = env["PATH_INFO"].scan(regexp).first.first
    request = Rack::Request.new(env)
    params = request.params
    params.symbolize_keys!

    if params and params[:rule_type]
      rule = RecurringSelect.dirty_hash_to_rule(params)
      [200, {"Content-Type" => "text/html"}, [rule.to_s]]
    else
      [200, {"Content-Type" => "text/html"}, [""]]
    end
  else
    @app.call(env)
  end
end