rack-locale_memorable 1.0.0 → 1.1.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: fa0c01424f46339976170cf682e5bfa2dc9d9fa7d07dd43f8a879364b0aad2b3
4
- data.tar.gz: 15f3723e2480bf0383cc10f34c5fe317006ecde186f89ec25846db244e69194c
3
+ metadata.gz: 9efbac61d08eec634b8977fc7c223f50c6dcd6cba0cfd09d7b368c3bd9f8eee9
4
+ data.tar.gz: e5c23a00f8386c708e24b3279c91c15bf71631153ece153c1904995f326424fa
5
5
  SHA512:
6
- metadata.gz: b18e7390e5a87613d9b67f4373587ea38b412396698f1f25f3f5cebb6b094d637616b13177733bb9c1e2968c534763953f7490ff1eea4915ebc9eca9fd067d8e
7
- data.tar.gz: ed28ed315f1f27d1e6f6780a7ab2117a848cff1f609247baf806189d995eacc56c397890c524abf28438dbd4a9e482b4a006dcea8205268c5b0379faa417d9ad
6
+ metadata.gz: a3fced878df7d908990f9962c18375e39b9c569f687bb07ef53bb53870154ca248e7bcea5a660c9689df8562140d64a8a0f5f0a29eefa2bfe451cb487549ffb9
7
+ data.tar.gz: 68b01b69ed47d96825a705d65fd234ce4e703ac93ded7c8f646ba4aeb82ef3b4c68b4421b4f8a1746cac2fc6c8d5d00fd30085c7e08352d524a794b55899350a
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Handle query params, cookie and HTTP_ACCEPT_LANGUAGE header to detect user-preffered locale, and remember it when necessary.
4
4
 
5
- Since some libraries (e.g., Devise & Warden) handles i18n strings in rack-middleware layer, setting `I18n.locale` is not enough for some cases.
5
+ Since some libraries (e.g., Devise & Warden) or applications may handle i18n strings in rack-middleware layer, setting `I18n.locale` in Rails layer is not enough in such cases.
6
6
 
7
7
  This gem sets `I18n.locale` in rack-middleware layer, so that you can let other rack-middlewares use proper `I18n.locale`.
8
8
 
@@ -40,6 +40,7 @@ There are several customizable options listed below.
40
40
  * `cookie_options[:path]` (`/` by default)
41
41
  * `cookie_options[:http_only]` (`true` by default)
42
42
  * `cookie_options[:secure]` (`true` by default)
43
+ * `cookie_options[:same_site]` (`nil` by default)
43
44
 
44
45
  You can customize them like below
45
46
 
@@ -54,13 +55,14 @@ Rails.application.configure do |config|
54
55
  domain: 'example.com',
55
56
  path: '/localized',
56
57
  http_only: false,
57
- secure: Rails.env.production?
58
+ secure: Rails.env.production?,
59
+ same_site :none
58
60
  }
59
61
  )
60
62
  end
61
63
  ```
62
64
 
63
- NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you see warden error messages in wrong locale.
65
+ NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you might see warden error messages in wrong locale.
64
66
 
65
67
  ```ruby
66
68
  Rails.application.configure do |config|
data/Rakefile CHANGED
@@ -5,4 +5,16 @@ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
+ namespace :coverage do
9
+ desc "Open coverage report"
10
+ task :report do
11
+ require 'simplecov'
12
+ `open "#{File.join SimpleCov.coverage_path, 'index.html'}"`
13
+ end
14
+ end
15
+
16
+ task :spec do
17
+ Rake::Task[:'coverage:report'].invoke unless ENV['GITHUB_ACTIONS']
18
+ end
19
+
8
20
  task default: :spec
@@ -3,14 +3,15 @@
3
3
  module Rack
4
4
  class LocaleMemorable
5
5
  class Response < Rack::Response
6
- def remember_locale(explicit_locale, key:, lifetime: 31536000, domain: nil, path: '/', http_only: true, secure: true)
6
+ def remember_locale(explicit_locale, key:, lifetime: 31536000, domain: nil, path: '/', http_only: true, secure: true, same_site: nil)
7
7
  set_cookie key, {
8
8
  value: explicit_locale,
9
9
  expires: Time.at(Time.now.to_i + lifetime.to_i),
10
10
  domain: domain,
11
11
  path: path,
12
12
  http_only: http_only,
13
- secure: secure
13
+ secure: secure,
14
+ same_site: same_site
14
15
  }.compact
15
16
  end
16
17
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class LocaleMemorable
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
@@ -15,7 +15,7 @@ module Rack
15
15
 
16
16
  def call(env)
17
17
  request = Request.new env
18
- I18n.with_locale(request.detect_locale params_key: @params_key, cookie_key: @cookie_key) do
18
+ I18n.with_locale request.detect_locale(params_key: @params_key, cookie_key: @cookie_key) do
19
19
  env['rack.locale'] = I18n.locale.to_s
20
20
  status, headers, body = @app.call(env)
21
21
  response = Response.new body, status, headers
@@ -15,8 +15,8 @@ Gem::Specification.new do |spec|
15
15
  spec.required_ruby_version = '>= 2.7.0'
16
16
 
17
17
  spec.metadata['homepage_uri'] = spec.homepage
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/blob/main/CHANGELOG.md'
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+ spec.metadata['changelog_uri'] = File.join(spec.homepage, '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: 1.0.0
4
+ version: 1.1.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-10-01 00:00:00.000000000 Z
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -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.3.7
166
+ rubygems_version: 3.3.26
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Remember locale in rack layer