rack-locale_memorable 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee932ccf31e17732f87bcbf4db7647cae4836b1424d85097da281ffe1ffaeddf
4
- data.tar.gz: 9c807857bf6296170af7746df724aa24d90ff9f7fb22d4c41b508f365da51cda
3
+ metadata.gz: 55bce36ab6b80c79c3057df44cbb98797093e1a10fba2d7f4614391a1472d0f2
4
+ data.tar.gz: feec52c485b6fe3056cc15c2137193d04a1430b058d84b53e42e91d25b173e0a
5
5
  SHA512:
6
- metadata.gz: 4ba6eff0fbb1cd813a1ad908cea006779858702d63911592679893060b10ba0c464cef63d7a493ef366aaedac558fa85f492cbd9f6653b06de8e5baebac7ae97
7
- data.tar.gz: ac2e798b0ac97a176af482b78f260eae3ece611c197f2435196895c869127d7cf2beb0c25d0798e5858003d369be131e7d2a097cbe8d11790a133755cb2082c6
6
+ metadata.gz: 5810a02bef7643ccd1c59fb4668813085ad223f7127985d7fb779b13c71438099fdf7f902b43aa0d784d9607d40e05ff402182bf20ae072c12b4244633368fa1
7
+ data.tar.gz: d9f6b533cace763569959f1431bf34f68988b91717e9c85b87ef56fa46bd84b3d853ec4d78222d438d507ce72220dfcda77924bf91d3cc920cf7145cb0e82394
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2022-09-28
4
+
5
+ ### Changed
6
+
7
+ - change cookie option interface and add spec for customizable options https://github.com/nov/rack-locale_memorable/commit/e25350bd045db2369233ec293fece73b571d652b
8
+
3
9
  ## [0.3.4] - 2022-09-28
4
10
 
5
11
  ### Fixed
data/README.md CHANGED
@@ -29,10 +29,13 @@ By default, this gem handles locale variables in 3 places in the order below, an
29
29
 
30
30
  There are several customizable options listed below.
31
31
 
32
- * params_key (`'locale'` by default)
33
- * cookie_key (`'locale'` by default)
34
- * secure_cookie (`true` by default)
35
- * cookie_lifetime (`1.year` by default)
32
+ * `params_key` (`'locale'` by default)
33
+ * `cookie_key` (`'locale'` by default)
34
+ * `cookie_options[:lifetime]` (`1.year` by default)
35
+ * `cookie_options[:domain]` (`nil` by default)
36
+ * `cookie_options[:path]` (`nil` by default)
37
+ * `cookie_options[:http_only]` (`true` by default)
38
+ * `cookie_options[:secure]` (`true` by default)
36
39
 
37
40
  You can customize them like below
38
41
 
@@ -42,8 +45,13 @@ Rails.application.configure do |config|
42
45
  Rack::LocaleMemorable,
43
46
  params_key: 'ui_locale',
44
47
  cookie_key: 'ui_locale',
45
- secure_cookie: Rails.env.production?,
46
- cookie_lifetime: 3.months
48
+ cookie_options: {
49
+ lifetime: 3.months,
50
+ domain: 'example.com',
51
+ path: '/localized',
52
+ http_only: false,
53
+ secure: Rails.env.production?
54
+ }
47
55
  )
48
56
  end
49
57
  ```
@@ -3,13 +3,15 @@
3
3
  module Rack
4
4
  class LocaleMemorable
5
5
  class Response < Rack::Response
6
- def remember_locale(explicit_locale, secure_cookie:, cookie_lifetime:, cookie_key:)
7
- set_cookie cookie_key, {
8
- value: explicit_locale,
9
- expires: cookie_lifetime.from_now,
10
- http_only: true,
11
- secure: secure_cookie
12
- }
6
+ def remember_locale(explicit_locale, key:, lifetime: 1.year, domain: nil, path: nil, http_only: true, secure: true)
7
+ set_cookie key, {
8
+ value: explicit_locale,
9
+ expires: lifetime.from_now,
10
+ domain: domain,
11
+ path: path,
12
+ http_only: http_only,
13
+ secure: secure
14
+ }.compact
13
15
  end
14
16
  end
15
17
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class LocaleMemorable
5
- VERSION = '0.3.4'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -7,12 +7,11 @@ require 'rack'
7
7
 
8
8
  module Rack
9
9
  class LocaleMemorable
10
- def initialize(app, params_key: 'locale', cookie_key: 'locale', secure_cookie: true, cookie_lifetime: 1.year)
10
+ def initialize(app, params_key: 'locale', cookie_key: 'locale', cookie_options: {})
11
11
  @app = app
12
12
  @params_key = params_key
13
13
  @cookie_key = cookie_key
14
- @secure_cookie = secure_cookie
15
- @cookie_lifetime = cookie_lifetime
14
+ @cookie_options = cookie_options
16
15
  end
17
16
 
18
17
  def call(env)
@@ -23,9 +22,7 @@ module Rack
23
22
  if request.explicit_locale.present?
24
23
  response.remember_locale(
25
24
  request.explicit_locale,
26
- secure_cookie: @secure_cookie,
27
- cookie_lifetime: @cookie_lifetime,
28
- cookie_key: @cookie_key
25
+ **@cookie_options.merge(key: @cookie_key)
29
26
  )
30
27
  end
31
28
  response.finish
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'rspec'
38
38
  spec.add_development_dependency 'simplecov'
39
39
  spec.add_development_dependency 'rack-test'
40
+ spec.add_development_dependency 'timecop'
40
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-locale_memorable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Remember locale in rack layer
126
140
  email:
127
141
  - nov@matake.jp