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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +14 -6
- data/lib/rack/locale_memorable/response.rb +9 -7
- data/lib/rack/locale_memorable/version.rb +1 -1
- data/lib/rack/locale_memorable.rb +3 -6
- data/rack-locale_memorable.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55bce36ab6b80c79c3057df44cbb98797093e1a10fba2d7f4614391a1472d0f2
|
4
|
+
data.tar.gz: feec52c485b6fe3056cc15c2137193d04a1430b058d84b53e42e91d25b173e0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
*
|
35
|
-
*
|
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
|
-
|
46
|
-
|
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,
|
7
|
-
set_cookie
|
8
|
-
value:
|
9
|
-
expires:
|
10
|
-
|
11
|
-
|
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
|
@@ -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',
|
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
|
-
@
|
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
|
-
|
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
|
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.
|
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
|