rack-locale_memorable 0.2.1 → 0.2.2

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: 7f2df24f2eaa2875b1e3894683850a222607d87ee81a44b5701a61afd11deb68
4
- data.tar.gz: 4d721669bd3d96b936ec29ec5daf22d7e4a5a15e93afcbbf7326def7d641ce7f
3
+ metadata.gz: c5d66845b0ecc18ec3afd2e985bad0d29533f031cad50f4a214b3273ccf21634
4
+ data.tar.gz: f4c1190527981fc0a17899539ceaf0cb954a68276b18cef39990e3f881a7eba9
5
5
  SHA512:
6
- metadata.gz: 0abca86a452ad7f38337f795cba0955b4a22b28920abf0101f2cc6e31dcb3491b3628597a6da5d5c1a71d1aa92fd423cf2caec2773c416a4664fa7ef4001feec
7
- data.tar.gz: 541fffff531d61b33d133e0c0ccd10991c1a1c48539e8ba7fc75f7fd01049eaefc833fe700606d39df71e8369d34ae97d36541c803b3468557b3a17bb9d7a32f
6
+ metadata.gz: 2bfa002397c86cd7c82a92b01d0ae56102869e65a4c20f7bc92b50128c12badf4692e6a42ded5008b60dac58f8290c2e77280a55d1674edc7daf71a3d374f16c
7
+ data.tar.gz: 0ca6c6d961aa210f709545e0610c5e6f3d29abb983e262484e9f133d4ac2b93ee40df9e5d6dad724d6e36ef6b4b8ce6e9a07d982ea68e7bb503bfa93d6f55488
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-28
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at matake.nobukazu@moneyforward.co.jp. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rack-locale_memorable.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 nov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Rack::LocaleMemorable
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rack/locale_memorable`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add rack-locale_memorable
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install rack-locale_memorable
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nov/rack-locale_memorable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nov/rack-locale_memorable/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Rack::LocaleMemorable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nov/rack-locale_memorable/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ class LocaleMemorable
5
+ class Request < Rack::Request
6
+ attr_reader :explicit_locale
7
+
8
+ def detect_locale
9
+ (
10
+ from_params ||
11
+ from_cookies ||
12
+ from_headers
13
+ )
14
+ end
15
+
16
+ private
17
+
18
+ def from_params
19
+ @explicit_locale = primary_locale_from params['locale']
20
+ end
21
+
22
+ def from_cookies
23
+ primary_locale_from cookies['locale']
24
+ end
25
+
26
+ def from_headers
27
+ primary_locale_from get_header('HTTP_ACCEPT_LANGUAGE')
28
+ end
29
+
30
+ def primary_locale_from(locales)
31
+ available_locales_from(locales)&.first if locales.present?
32
+ end
33
+
34
+ def available_locales_from(locales)
35
+ (
36
+ HTTP::Accept::Languages::Locales.new(I18n.available_locales.map(&:to_s)) &
37
+ HTTP::Accept::Languages.parse(
38
+ HTTP::Accept::Languages::Locales.new(
39
+ HTTP::Accept::Languages.parse(locales).collect(&:locale)
40
+ ).patterns.keys.join(',')
41
+ )
42
+ )
43
+ rescue
44
+ nil
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ class LocaleMemorable
5
+ class Response < Rack::Response
6
+ def remember_locale(explicit_locale, secure_cookie:, cookie_expiry:)
7
+ set_cookie 'locale', {
8
+ value: explicit_locale,
9
+ expires: cookie_expiry,
10
+ http_only: true,
11
+ secure: secure_cookie
12
+ }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ class LocaleMemorable
5
+ VERSION = '0.2.2'
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'active_support/all'
5
+ require 'http/accept'
6
+ require 'rack'
7
+
8
+ module Rack
9
+ class LocaleMemorable
10
+ def initialize(app, secure_cookie: true, cookie_expiry: 1.year.from_now)
11
+ @app = app
12
+ @secure_cookie = secure_cookie
13
+ @cookie_expiry = cookie_expiry
14
+ end
15
+
16
+ def call(env)
17
+ request = Request.new(env)
18
+ I18n.with_locale(request.detect_locale) do
19
+ status, headers, body = @app.call(env)
20
+ response = Response.new body, status, headers
21
+ if request.explicit_locale.present?
22
+ response.remember_locale(
23
+ request.explicit_locale,
24
+ secure_cookie: @secure_cookie,
25
+ cookie_expiry: @cookie_expiry
26
+ )
27
+ end
28
+ response.finish
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ require_relative 'locale_memorable/version'
35
+ require_relative 'locale_memorable/request'
36
+ require_relative 'locale_memorable/response'
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rack/locale_memorable/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rack-locale_memorable'
7
+ spec.version = Rack::LocaleMemorable::VERSION
8
+ spec.authors = ['nov']
9
+ spec.email = ['nov@matake.jp']
10
+
11
+ spec.summary = 'Remember locale in rack layer'
12
+ spec.description = 'Remember locale in rack layer'
13
+ spec.homepage = 'https://github.com/nov/rack-locale_memorable'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.7.0'
16
+
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/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'rack'
33
+ spec.add_dependency 'i18n'
34
+ spec.add_dependency 'http-accept'
35
+ spec.add_dependency 'activesupport'
36
+ spec.add_development_dependency 'rake'
37
+ spec.add_development_dependency 'rspec'
38
+ spec.add_development_dependency 'simplecov'
39
+ spec.add_development_dependency 'rack-test'
40
+ end
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov
@@ -128,7 +128,19 @@ email:
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
- files: []
131
+ files:
132
+ - ".rspec"
133
+ - CHANGELOG.md
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - lib/rack/locale_memorable.rb
140
+ - lib/rack/locale_memorable/request.rb
141
+ - lib/rack/locale_memorable/response.rb
142
+ - lib/rack/locale_memorable/version.rb
143
+ - rack-locale_memorable.gemspec
132
144
  homepage: https://github.com/nov/rack-locale_memorable
133
145
  licenses:
134
146
  - MIT
@@ -151,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
163
  - !ruby/object:Gem::Version
152
164
  version: '0'
153
165
  requirements: []
154
- rubygems_version: 3.1.6
166
+ rubygems_version: 3.3.7
155
167
  signing_key:
156
168
  specification_version: 4
157
169
  summary: Remember locale in rack layer