rack-locale_memorable 0.3.4 → 0.4.1

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: c5fa88bee1ecee1f29896cc46819466cc62ff1e673e709d727ed8a50a455ae0f
4
+ data.tar.gz: e19e763fe6ab18649ad21c50fbc8a0556f7b27020266114379815106c2d29ec7
5
5
  SHA512:
6
- metadata.gz: 4ba6eff0fbb1cd813a1ad908cea006779858702d63911592679893060b10ba0c464cef63d7a493ef366aaedac558fa85f492cbd9f6653b06de8e5baebac7ae97
7
- data.tar.gz: ac2e798b0ac97a176af482b78f260eae3ece611c197f2435196895c869127d7cf2beb0c25d0798e5858003d369be131e7d2a097cbe8d11790a133755cb2082c6
6
+ metadata.gz: 16175263afb06a7ab63088895a78d9112f10d0b9f1e384fd1481c56c0acf1a44ea5b16f1e7f1cb3e439945020d533fb8179976b768d190a1ce431bde4a55493c
7
+ data.tar.gz: 9099bd43efbf47653789c4c679ff805561d9b90d4562991176dc16fa6cb5492d569acd8cf63382079a25f2d94b1b1ba8d7fa50f1e489ef3d5477aa48b8344745
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.1] - 2022-09-29
4
+
5
+ ### Fixed
6
+
7
+ - make default path "/" https://github.com/nov/rack-locale_memorable/commit/439868e4d2f6a917be1234fa2d9bdbfab41fce69
8
+
9
+
10
+ ## [0.4.0] - 2022-09-28
11
+
12
+ ### Changed
13
+
14
+ - change cookie option interface and add spec for customizable options https://github.com/nov/rack-locale_memorable/commit/e25350bd045db2369233ec293fece73b571d652b
15
+
3
16
  ## [0.3.4] - 2022-09-28
4
17
 
5
18
  ### 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: '/', 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.1'
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,14 +1,14 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2022-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -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