Class: Padrino::AuthenticityToken

Inherits:
Rack::Protection::AuthenticityToken
  • Object
show all
Defined in:
padrino-core/lib/padrino-core/application/authenticity_token.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ AuthenticityToken

Returns a new instance of AuthenticityToken



3
4
5
6
7
8
# File 'padrino-core/lib/padrino-core/application/authenticity_token.rb', line 3

def initialize(app, options = {})
  @app = app
  @except = options[:except]
  @except = Array(@except) unless @except.is_a?(Proc)
  super
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
# File 'padrino-core/lib/padrino-core/application/authenticity_token.rb', line 10

def call(env)
  if except?(env)
    @app.call(env)
  else
    super
  end
end

#except?(env) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'padrino-core/lib/padrino-core/application/authenticity_token.rb', line 18

def except?(env)
  return false unless @except
  path_info = env['PATH_INFO']
  @except.is_a?(Proc) ? @except.call(env) : @except.any?{|path|
    path.is_a?(Regexp) ? path.match(path_info) : path == path_info }
end