Class: Grape::Cookies::Middleware::EnvSetup
- Inherits:
-
Object
- Object
- Grape::Cookies::Middleware::EnvSetup
- Defined in:
- lib/grape/cookies/middleware/env_setup.rb
Class Method Summary collapse
- .key_generator ⇒ Object
- .reset_settings_for_env! ⇒ Object
- .settings ⇒ Object
- .settings_for_env ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ EnvSetup
constructor
A new instance of EnvSetup.
Constructor Details
#initialize(app) ⇒ EnvSetup
Returns a new instance of EnvSetup.
39 40 41 |
# File 'lib/grape/cookies/middleware/env_setup.rb', line 39 def initialize(app) @app = app end |
Class Method Details
.key_generator ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/grape/cookies/middleware/env_setup.rb', line 10 def self.key_generator @caching_key_generator ||= begin if settings[:secret_key_base].blank? raise ArgumentError, 'A secret is required to generate an integrity hash ' \ 'for cookie session data. Set a secret_key_base.' end key_generator = ActiveSupport::KeyGenerator.new(settings[:secret_key_base], iterations: 1000) ActiveSupport::CachingKeyGenerator.new(key_generator) end end |
.reset_settings_for_env! ⇒ Object
34 35 36 37 |
# File 'lib/grape/cookies/middleware/env_setup.rb', line 34 def self.reset_settings_for_env! @caching_key_generator = nil @settings_for_env = nil end |
.settings ⇒ Object
6 7 8 |
# File 'lib/grape/cookies/middleware/env_setup.rb', line 6 def self.settings Cookies.settings end |
.settings_for_env ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/grape/cookies/middleware/env_setup.rb', line 22 def self.settings_for_env @settings_for_env ||= { ActionDispatch::Cookies::GENERATOR_KEY => key_generator, ActionDispatch::Cookies::SIGNED_COOKIE_SALT => settings[:signed_cookie_salt], ActionDispatch::Cookies::ENCRYPTED_COOKIE_SALT => settings[:encrypted_cookie_salt], ActionDispatch::Cookies::ENCRYPTED_SIGNED_COOKIE_SALT => settings[:encrypted_signed_cookie_salt], ActionDispatch::Cookies::SECRET_TOKEN => settings[:secret_token], ActionDispatch::Cookies::SECRET_KEY_BASE => settings[:secret_key_base], ActionDispatch::Cookies::COOKIES_SERIALIZER => settings[:cookies_serializer] }.freeze end |
Instance Method Details
#call(env) ⇒ Object
43 44 45 46 47 |
# File 'lib/grape/cookies/middleware/env_setup.rb', line 43 def call(env) env.merge!(self.class.settings_for_env) @app.call(env) end |