class Rack::RestfulSubmit

Constants

REWRITE_KEYWORD
REWRITE_MAP

Public Class Methods

new(app) click to toggle source
# File lib/rack/rack-restful_submit.rb, line 7
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/rack-restful_submit.rb, line 11
def call(env)
  if env["REQUEST_METHOD"] == "POST"
    req = Request.new(env)

    if req.params[REWRITE_KEYWORD] && req.params[REWRITE_MAP]
      action = req.params[REWRITE_KEYWORD].keys.first # Should be always just one.
      mapping = req.params[REWRITE_MAP][action]

      if mapping && mapping['url'] && mapping['method']
        rewrite(env, mapping['url'], mapping['method'])
      else
        return super(env)
      end
    else
      return super(env)
    end
  end

  @app.call(env)
end