Exception: TrustedKeys::Error::NotTrusted
- Inherits:
-
StandardError
- Object
- StandardError
- TrustedKeys::Error::NotTrusted
- Defined in:
- lib/trusted_keys/error/not_trusted.rb
Instance Method Summary collapse
-
#initialize(env) ⇒ NotTrusted
constructor
A new instance of NotTrusted.
- #keys(options) ⇒ Object
- #message ⇒ Object
- #present? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ NotTrusted
Returns a new instance of NotTrusted.
4 5 6 7 |
# File 'lib/trusted_keys/error/not_trusted.rb', line 4 def initialize(env) @keys = {} @production = not(env.development? or env.test?) end |
Instance Method Details
#keys(options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/trusted_keys/error/not_trusted.rb', line 18 def keys() scope = .fetch(:scope) key = .fetch(:key) keys = .fetch(:keys).flatten.map do |key| ":#{key.to_s.sub(/\(\di\)/, '')}" end.uniq.join(', ') scope_key = (scope + [key]).compact.join('.') @keys[scope_key] = keys unless scope_key.empty? self end |
#message ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/trusted_keys/error/not_trusted.rb', line 9 def usage = @keys.map do |scope, keys| "`trust #{keys}, for: '#{scope}'`" end.join("\n") "\n\nError: There are keys in the params hash that are not trusted. " + "Set them as trusted with:\n#{usage} at the top of the controller." end |
#present? ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/trusted_keys/error/not_trusted.rb', line 31 def present? if @production false else not @keys.empty? end end |