rack-locale_memorable 0.3.3 → 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: 51ae9ed5a060ebb4263d0faeded7a6bdd94d40abb9835c670ce500e278ae5ac1
4
- data.tar.gz: 758bc0cf5ac3498be41d78b79382024752d8a7ebb5995c0097b16031dacf4d86
3
+ metadata.gz: 55bce36ab6b80c79c3057df44cbb98797093e1a10fba2d7f4614391a1472d0f2
4
+ data.tar.gz: feec52c485b6fe3056cc15c2137193d04a1430b058d84b53e42e91d25b173e0a
5
5
  SHA512:
6
- metadata.gz: a6f73bce4a3940de8115d561cb2a3785f143e48496ba0822a186257122a3b8e4a0e2de1bc84ef5466da5cb0862fdcf5e410520d0d949100f7cfecfefad9e1a15
7
- data.tar.gz: e38a7bd143e65235b55af8b05897135d04ca897ba0fdac1892e66b992005f7e81517a3265924bbba210860451abd8c39e9d5c756f029a5299bd9c98831599027
6
+ metadata.gz: 5810a02bef7643ccd1c59fb4668813085ad223f7127985d7fb779b13c71438099fdf7f902b43aa0d784d9607d40e05ff402182bf20ae072c12b4244633368fa1
7
+ data.tar.gz: d9f6b533cace763569959f1431bf34f68988b91717e9c85b87ef56fa46bd84b3d853ec4d78222d438d507ce72220dfcda77924bf91d3cc920cf7145cb0e82394
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
9
+ ## [0.3.4] - 2022-09-28
10
+
11
+ ### Fixed
12
+
13
+ - fix changelog url https://github.com/nov/rack-locale_memorable/commit/fc744c6fe1489cee12225b8cc5991a9f4d797278
14
+
3
15
  ## [0.3.3] - 2022-09-28
4
16
 
5
17
  ### Refactored
data/README.md CHANGED
@@ -21,29 +21,23 @@ Rails.application.configure do |config|
21
21
  end
22
22
  ```
23
23
 
24
- NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you see warden error messages in wrong locale.
25
-
26
- ```ruby
27
- Rails.application.configure do |config|
28
- config.middleware.insert_before Warden::Manager, Rack::LocaleMemorable
29
- end
30
- ```
31
-
32
- By default, this gem handles
24
+ By default, this gem handles locale variables in 3 places in the order below, and when explicit locale is specified (= when locale is specified via query params) in the request, remember it in cookie too.
33
25
 
34
- * `params['locale']` as explicit locale
35
- * `cookies['locale']` as remembered locale
36
- * `headers['HTTP_ACCEPT_LANGUAGE']` as implicit locale
26
+ 1. `params['locale']` as explicit locale
27
+ 2. `cookies['locale']` as remembered locale
28
+ 3. `headers['HTTP_ACCEPT_LANGUAGE']` as implicit locale
37
29
 
38
- and when explicit locale is specified in the request, remember it in cookie.
30
+ There are several customizable options listed below.
39
31
 
40
- You can customize those values
41
- * params_key (`'locale'` by default)
42
- * cookie_key (`'locale'` by default)
43
- * secure_cookie (`true` by default)
44
- * 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)
45
39
 
46
- like below
40
+ You can customize them like below
47
41
 
48
42
  ```ruby
49
43
  Rails.application.configure do |config|
@@ -51,12 +45,25 @@ Rails.application.configure do |config|
51
45
  Rack::LocaleMemorable,
52
46
  params_key: 'ui_locale',
53
47
  cookie_key: 'ui_locale',
54
- secure_cookie: Rails.env.production?,
55
- 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
+ }
56
55
  )
57
56
  end
58
57
  ```
59
58
 
59
+ NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you see warden error messages in wrong locale.
60
+
61
+ ```ruby
62
+ Rails.application.configure do |config|
63
+ config.middleware.insert_before Warden::Manager, Rack::LocaleMemorable
64
+ end
65
+ ```
66
+
60
67
  ## Development
61
68
 
62
69
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -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.3'
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
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
18
  spec.metadata['source_code_uri'] = 'https://github.com/nov/rack-locale_memorable'
19
- spec.metadata['changelog_uri'] = 'https://github.com/nov/rack-locale_memorable/CHANGELOG.md'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/nov/rack-locale_memorable/blob/main/CHANGELOG.md'
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -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.3
4
+ version: 0.4.0
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-27 00:00:00.000000000 Z
11
+ date: 2022-09-28 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
@@ -147,7 +161,7 @@ licenses:
147
161
  metadata:
148
162
  homepage_uri: https://github.com/nov/rack-locale_memorable
149
163
  source_code_uri: https://github.com/nov/rack-locale_memorable
150
- changelog_uri: https://github.com/nov/rack-locale_memorable/CHANGELOG.md
164
+ changelog_uri: https://github.com/nov/rack-locale_memorable/blob/main/CHANGELOG.md
151
165
  post_install_message:
152
166
  rdoc_options: []
153
167
  require_paths: