rack-locale_memorable 0.3.2 → 0.3.4

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: 5ccb7d078d2dd4d582f7db663cf0436da123b94e6531f8d6de83a63c1eb03bbd
4
- data.tar.gz: eb20d6db30ef828dfac9f27843ab9a249308c889835f912e61986d1f08f1edc9
3
+ metadata.gz: ee932ccf31e17732f87bcbf4db7647cae4836b1424d85097da281ffe1ffaeddf
4
+ data.tar.gz: 9c807857bf6296170af7746df724aa24d90ff9f7fb22d4c41b508f365da51cda
5
5
  SHA512:
6
- metadata.gz: 5b6212b7c2a58b6f110a22856ac52c8197600ccc9929f229147f8324d6342a15e5472ef45917fe11dfbdd2bf196877fd8b5e26f962cfa9668b95d7622b77cd8d
7
- data.tar.gz: 6fdd32c5bad90120d759514971c20b2de1330fbc9774bbf218cd91a7781cfffb89f2a29f3da5547452b4ae1cede23d757d6b25ca345429cb7b5f81b6f98f0eae
6
+ metadata.gz: 4ba6eff0fbb1cd813a1ad908cea006779858702d63911592679893060b10ba0c464cef63d7a493ef366aaedac558fa85f492cbd9f6653b06de8e5baebac7ae97
7
+ data.tar.gz: ac2e798b0ac97a176af482b78f260eae3ece611c197f2435196895c869127d7cf2beb0c25d0798e5858003d369be131e7d2a097cbe8d11790a133755cb2082c6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.4] - 2022-09-28
4
+
5
+ ### Fixed
6
+
7
+ - fix changelog url https://github.com/nov/rack-locale_memorable/commit/fc744c6fe1489cee12225b8cc5991a9f4d797278
8
+
9
+ ## [0.3.3] - 2022-09-28
10
+
11
+ ### Refactored
12
+
13
+ - requre active_support/core_ext only https://github.com/nov/rack-locale_memorable/commit/bf56b49f064a30d9688d65d2dd2901763bf31cee
14
+ - stop using request class's instance variables following response class's design https://github.com/nov/rack-locale_memorable/commit/056807010fcb5c01d4d1745f06f8a9f87aad2ec6
15
+
3
16
  ## [0.3.2] - 2022-09-28
4
17
 
5
18
  ### Fixed
data/README.md CHANGED
@@ -21,29 +21,20 @@ 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
32
  * params_key (`'locale'` by default)
42
33
  * cookie_key (`'locale'` by default)
43
34
  * secure_cookie (`true` by default)
44
35
  * cookie_lifetime (`1.year` by default)
45
36
 
46
- like below
37
+ You can customize them like below
47
38
 
48
39
  ```ruby
49
40
  Rails.application.configure do |config|
@@ -57,6 +48,14 @@ Rails.application.configure do |config|
57
48
  end
58
49
  ```
59
50
 
51
+ NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you see warden error messages in wrong locale.
52
+
53
+ ```ruby
54
+ Rails.application.configure do |config|
55
+ config.middleware.insert_before Warden::Manager, Rack::LocaleMemorable
56
+ end
57
+ ```
58
+
60
59
  ## Development
61
60
 
62
61
  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,30 +3,24 @@
3
3
  module Rack
4
4
  class LocaleMemorable
5
5
  class Request < Rack::Request
6
- attr_reader :explicit_locale, :params_key, :cookie_key
6
+ attr_reader :explicit_locale
7
7
 
8
- def initialize(env, params_key:, cookie_key:)
9
- super env
10
- @params_key = params_key
11
- @cookie_key = cookie_key
12
- end
13
-
14
- def detect_locale
8
+ def detect_locale(params_key:, cookie_key:)
15
9
  (
16
- from_params ||
17
- from_cookies ||
10
+ from_params(params_key) ||
11
+ from_cookies(cookie_key) ||
18
12
  from_headers
19
13
  )
20
14
  end
21
15
 
22
16
  private
23
17
 
24
- def from_params
25
- @explicit_locale = primary_locale_from params[params_key]
18
+ def from_params(key)
19
+ @explicit_locale = primary_locale_from params[key]
26
20
  end
27
21
 
28
- def from_cookies
29
- primary_locale_from cookies[cookie_key]
22
+ def from_cookies(key)
23
+ primary_locale_from cookies[key]
30
24
  end
31
25
 
32
26
  def from_headers
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class LocaleMemorable
5
- VERSION = '0.3.2'
5
+ VERSION = '0.3.4'
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support'
4
- require 'active_support/all'
4
+ require 'active_support/core_ext'
5
5
  require 'http/accept'
6
6
  require 'rack'
7
7
 
@@ -16,8 +16,8 @@ module Rack
16
16
  end
17
17
 
18
18
  def call(env)
19
- request = Request.new(env, params_key: @params_key, cookie_key: @cookie_key)
20
- I18n.with_locale(request.detect_locale) do
19
+ request = Request.new env
20
+ I18n.with_locale(request.detect_locale params_key: @params_key, cookie_key: @cookie_key) do
21
21
  status, headers, body = @app.call(env)
22
22
  response = Response.new body, status, headers
23
23
  if request.explicit_locale.present?
@@ -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.
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.2
4
+ version: 0.3.4
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
@@ -147,7 +147,7 @@ licenses:
147
147
  metadata:
148
148
  homepage_uri: https://github.com/nov/rack-locale_memorable
149
149
  source_code_uri: https://github.com/nov/rack-locale_memorable
150
- changelog_uri: https://github.com/nov/rack-locale_memorable/CHANGELOG.md
150
+ changelog_uri: https://github.com/nov/rack-locale_memorable/blob/main/CHANGELOG.md
151
151
  post_install_message:
152
152
  rdoc_options: []
153
153
  require_paths:
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubygems_version: 3.1.6
166
+ rubygems_version: 3.3.7
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Remember locale in rack layer