Class: TurboBoost::Commands::TokenValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_boost/commands/token_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, method_name) ⇒ TokenValidator

Returns a new instance of TokenValidator.



4
5
6
7
# File 'lib/turbo_boost/commands/token_validator.rb', line 4

def initialize(command, method_name)
  @command = command
  @method_name = method_name
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/turbo_boost/commands/token_validator.rb', line 9

def command
  @command
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



9
10
11
# File 'lib/turbo_boost/commands/token_validator.rb', line 9

def method_name
  @method_name
end

Instance Method Details

#validateObject Also known as: valid?



13
14
15
16
# File 'lib/turbo_boost/commands/token_validator.rb', line 13

def validate
  return true unless TurboBoost::Commands.config.protect_from_forgery
  tokens.any? { |token| valid_token? token }
end

#validate!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/turbo_boost/commands/token_validator.rb', line 20

def validate!
  return true if valid?

  message = "    `\#{command.class.name}#\#{method_name}` invoked with an invalid authenticity token!\n\n    Verify that your page includes `<%= csrf_meta_tags %>` in the header.\n\n    If the problem persists, you can disable forgery protection with `TurboBoost::Commands.config.protect_from_forgery = false`\n  MSG\n\n  raise TurboBoost::Commands::InvalidTokenError.new(message, command: command.class)\nend\n"