i18n-dot_lookup 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: b4ab84a8459f24c2db3c073e280c84e78a7285d8
4
- data.tar.gz: e858b17e09147d9b9c99d29ca944a0787c7a4fa8
2
+ SHA256:
3
+ metadata.gz: e4f4d30542fe220f1bf7e6618667b1aa291fab639e827a495207d5a6b6fc36d4
4
+ data.tar.gz: 215042d0b793b12deca58c295e3d68980cbf7abdcaf5f560f352faa6d47ded2c
5
5
  SHA512:
6
- metadata.gz: dac66431e5d88673b1b5f68ee14f37b29ffa4390ac2890ce7a443569c027a651a251932ec1b77afe9d3882f866c8c2b56debb05479b648118ccb02dfd11ea437
7
- data.tar.gz: f1bdb3a3678133f6b1e1d3bf0b6edd2b283c33eefd5d92ef7bccae192cbb7d933c5c07ccef64273de90ca992866e956799253420ba3653131a9522422714bdf7
6
+ metadata.gz: 5c1919375728c718505820742bfc75225eab8ed4ef27ad1fa91f00b27eca1819491d7d0cdf51c3d45f2ec33005131108f6848508cd318212921b5fdf77913ed7
7
+ data.tar.gz: 75fd94d3fe4f44e3baa0b9fa7ff4051346af2a69fe661453d0cbbbf14d4afdb787ea8444997f8e9adb9f98b3f27e88212b7ad3767b528df81bd58a2a2252865d
@@ -0,0 +1,3 @@
1
+ ---
2
+ github: [fnando]
3
+ custom: ["https://www.paypal.me/nandovieira/🍕"]
@@ -0,0 +1,23 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+
9
+ Naming/FileName:
10
+ Exclude:
11
+ - lib/i18n-dot_lookup.rb
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
15
+
16
+ Metrics/CyclomaticComplexity:
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Enabled: false
@@ -2,7 +2,11 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
- - 2.2.2
5
+ - 2.7.1
6
+ - 2.6.5
6
7
  before_install: gem install bundler
7
8
  notifications:
8
9
  email: false
10
+ env:
11
+ global:
12
+ secure: ajBIIzw0/L1Hpt/NQXL8UKUpJVOZBRLDMiRC4SAiEWpoDpl3HsIpyyq/D7EyzOUtwZCvxEBO7w0WtbfQ2pqjjuBPsNof5IMtYprng0lMKqQ8VkO59uAJsY4If1bOk1a729hpeo9aVr4PqW478gg5IYVVC+ymJ8m6WOnmDWDS7A1sxIs/M9/52kYGWzdDrwsMo0qRXqg+1AI+/dXCpXHtWgp5T9oNa3AVAvM50umsJRkio9p2WtWnTWADVkeu1xli8Td6yWhujRdUyK2bfdSI6o6eI6yUQVxqhoAlC6HIxfQQmhhXCIs4pd1d6hiQXDVwpMVt9UvVK2yQJL6+DLXCQto+YS7OzbSq98FCrp8637Pl8XF5Le2iUFy2tzcasCwTgfgI20CzxxWQkYN/xWjZtT43sx+nagjzi8GHzfR9jee8ttSlbIx/8brP3h/l9ylBVQISRId04u6drgEkk9It2ET58Ue+WNL0zOBRPgCnixmGvMMe6weFLi1WxbuLP0+FCc/EFnT1mEGbxWUiLNbDl3gDJUbfgVOsO4RmWvuTghIpJlcXv8E8aZsyHQBXia0jUCwVOgV2i0O8kDjHgLfY1QOmwKPrB8YE4uuIYNyZL2sPJyn2inKEmzovQHSl5gbFk+Z9AD72zpNleHiPL1F8esbtiN4Ud7VD5/6f4RXuADM=
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in i18n-dot_lookup.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # i18n-dot_lookup
2
2
 
3
- ![build status](https://travis-ci.org/fnando/i18n-dot_lookup.svg)
3
+ [![Travis-CI](https://travis-ci.org/fnando/i18n-dot_lookup.svg)](https://travis-ci.org/fnando/i18n-dot_lookup)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/i18n-dot_lookup/badges/gpa.svg)](https://codeclimate.com/github/fnando/i18n-dot_lookup)
5
+ [![Gem](https://img.shields.io/gem/v/i18n-dot_lookup.svg)](https://rubygems.org/gems/i18n-dot_lookup)
6
+ [![Gem](https://img.shields.io/gem/dt/i18n-dot_lookup.svg)](https://rubygems.org/gems/i18n-dot_lookup)
4
7
 
5
8
  Ever wanted to get properties from an object, like `%{user.name}`? Now you can!
6
9
 
@@ -9,7 +12,7 @@ Ever wanted to get properties from an object, like `%{user.name}`? Now you can!
9
12
  Add this line to your application's Gemfile:
10
13
 
11
14
  ```ruby
12
- gem 'i18n-dot_lookup'
15
+ gem "i18n-dot_lookup"
13
16
  ```
14
17
 
15
18
  And then execute:
@@ -23,29 +26,37 @@ Or install it yourself as:
23
26
  ## Usage
24
27
 
25
28
  ```ruby
26
- require 'i18n-dot_lookup'
27
- require 'ostruct'
29
+ require "i18n-dot_lookup"
30
+ require "ostruct"
28
31
 
29
32
  # You don't need to do this, but can use it to test on your console.
30
- I18n.backend.store_translations :en, {hello: 'hello %{user.name}'}
33
+ I18n.backend.store_translations :en, {hello: "hello %{user.name}"}
31
34
 
32
35
  # The user object will probably come from your database
33
- I18n.t :hello, user: OpenStruct.new(name: 'john')
36
+ I18n.t :hello, user: OpenStruct.new(name: "john")
34
37
  #=> hello john
35
38
  ```
36
39
 
37
40
  ## Development
38
41
 
39
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
43
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
44
+ prompt that will allow you to experiment.
40
45
 
41
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To
47
+ release a new version, update the version number in `version.rb`, and then run
48
+ `bundle exec rake release`, which will create a git tag for the version, push
49
+ git commits and tags, and push the `.gem` file to
50
+ [rubygems.org](https://rubygems.org).
42
51
 
43
52
  ## Contributing
44
53
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/i18n-dot_lookup. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
-
54
+ Bug reports and pull requests are welcome on GitHub at
55
+ https://github.com/fnando/i18n-dot_lookup. This project is intended to be a
56
+ safe, welcoming space for collaboration, and contributors are expected to adhere
57
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
58
 
48
59
  ## License
49
60
 
50
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
-
61
+ The gem is available as open source under the terms of the
62
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,10 +1,15 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "rubocop/rake_task"
3
6
 
4
7
  Rake::TestTask.new(:test) do |t|
5
- t.libs << 'test'
6
- t.libs << 'lib'
7
- t.test_files = FileList['test/**/*_test.rb']
8
+ t.libs << "test"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ t.warning = false
8
11
  end
9
12
 
10
- task :default => :test
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
@@ -1,24 +1,34 @@
1
- require './lib/i18n-dot_lookup/version'
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/i18n-dot_lookup/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.name = 'i18n-dot_lookup'
6
+ spec.name = "i18n-dot_lookup"
5
7
  spec.version = I18nDotLookup::VERSION
6
- spec.authors = ['Nando Vieira']
7
- spec.email = ['fnando.vieira@gmail.com']
8
+ spec.authors = ["Nando Vieira"]
9
+ spec.email = ["fnando.vieira@gmail.com"]
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
8
11
 
9
- spec.summary = "Allow interpolation to be performed on a object's attribute, e.g. %{user.name}"
12
+ spec.summary = "Allow interpolation to be performed on a object's "\
13
+ "attribute, e.g. %{user.name}"
10
14
  spec.description = spec.summary
11
- spec.homepage = 'https://github.com/fnando/i18n-dot_lookup'
12
- spec.license = 'MIT'
15
+ spec.homepage = "https://github.com/fnando/i18n-dot_lookup"
16
+ spec.license = "MIT"
13
17
 
14
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
- spec.require_paths = ['lib']
18
+ spec.files = `git ls-files -z`
19
+ .split("\x0")
20
+ .reject {|f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
17
23
 
18
- spec.add_dependency 'i18n'
19
- spec.add_development_dependency 'bundler', '~> 1.10'
20
- spec.add_development_dependency 'rake', '~> 10.0'
21
- spec.add_development_dependency 'minitest'
22
- spec.add_development_dependency 'minitest-utils'
23
- spec.add_development_dependency 'pry-meta'
24
+ spec.add_dependency "i18n"
25
+ spec.add_development_dependency "activesupport"
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "minitest"
28
+ spec.add_development_dependency "minitest-utils"
29
+ spec.add_development_dependency "pry-meta"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "rubocop"
32
+ spec.add_development_dependency "rubocop-fnando"
33
+ spec.add_development_dependency "simplecov"
24
34
  end
@@ -1,2 +1,9 @@
1
- require 'i18n/backend/dot_lookup'
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n/backend/dot_lookup"
2
4
  I18n.backend = I18n::Backend::DotLookup.new
5
+
6
+ if I18n.config.respond_to?(:interpolation_patterns)
7
+ I18n.config.interpolation_patterns <<
8
+ I18n::Backend::DotLookup::INTERPOLATION_PATTERN
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module I18nDotLookup
2
- VERSION = '0.1.0'
4
+ VERSION = "0.2.0"
3
5
  end
@@ -1,18 +1,24 @@
1
- require 'i18n'
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n"
2
4
 
3
5
  module I18n
4
6
  module Backend
5
7
  class DotLookup < Simple
6
- KEY_EXTRACTOR = /%\{(\w+(?:\.\w+)+)\}/
7
- UNKNOWN_PROPERTY = Object.new
8
- DOT = '.'.freeze
8
+ INTERPOLATION_PATTERN = /%\{(\w+(?:\.\w+)+)\}/.freeze
9
+ UNKNOWN_PROPERTY = Object.new
10
+ DOT = "."
9
11
 
10
- _verbose, $VERBOSE = $VERBOSE, nil
11
- ::I18n::INTERPOLATION_PATTERN = Regexp.union(KEY_EXTRACTOR, ::I18n::INTERPOLATION_PATTERN)
12
- $VERBOSE = _verbose
12
+ verbose = $VERBOSE
13
+ $VERBOSE = nil
14
+ ::I18n::INTERPOLATION_PATTERN =
15
+ Regexp.union(INTERPOLATION_PATTERN, ::I18n::INTERPOLATION_PATTERN)
16
+ $VERBOSE = verbose
13
17
 
14
18
  def translate(locale, key, options = {})
15
- raise InvalidLocale.new(locale) unless locale
19
+ raise InvalidLocale, locale unless locale
20
+
21
+ options = options.dup
16
22
  entry = key && lookup(locale, key, options[:scope], options)
17
23
 
18
24
  if options.empty?
@@ -20,14 +26,21 @@ module I18n
20
26
  else
21
27
  count, default = options.values_at(:count, :default)
22
28
  values = options.except(*RESERVED_KEYS)
23
- entry = entry.nil? && default ?
24
- default(locale, key, default, options) : resolve(locale, key, entry, options)
29
+
30
+ entry = if entry.nil? && default
31
+ default(locale, key, default, options)
32
+ else
33
+ resolve(locale, key, entry, options)
34
+ end
35
+ end
36
+
37
+ if entry.nil?
38
+ throw(:exception, I18n::MissingTranslation.new(locale, key, options))
25
39
  end
26
40
 
27
- throw(:exception, I18n::MissingTranslation.new(locale, key, options)) if entry.nil?
28
41
  entry = entry.dup if entry.is_a?(String)
29
42
 
30
- populate_options(entry, values) if entry.kind_of?(String)
43
+ populate_options(entry, values) if entry.is_a?(String)
31
44
  entry = pluralize(locale, entry, count) if count
32
45
  entry = interpolate(locale, entry, values) if values
33
46
  entry
@@ -43,16 +56,17 @@ module I18n
43
56
  end
44
57
 
45
58
  def extract_keys(subject)
46
- subject.scan(KEY_EXTRACTOR).flatten
59
+ subject.scan(INTERPOLATION_PATTERN).flatten
47
60
  end
48
61
 
49
62
  def get_value(object, keys)
50
- value = keys.inject(object) do |target, key|
51
- throw :unknown_property, UNKNOWN_PROPERTY unless target && target.respond_to?(key)
63
+ keys.inject(object) do |target, key|
64
+ unless target&.respond_to?(key)
65
+ throw :unknown_property, UNKNOWN_PROPERTY
66
+ end
67
+
52
68
  target.public_send(key)
53
69
  end
54
-
55
- value
56
70
  end
57
71
  end
58
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-dot_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,62 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-fnando
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'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
97
153
  description: Allow interpolation to be performed on a object's attribute, e.g. %{user.name}
98
154
  email:
99
155
  - fnando.vieira@gmail.com
@@ -101,7 +157,9 @@ executables: []
101
157
  extensions: []
102
158
  extra_rdoc_files: []
103
159
  files:
160
+ - ".github/FUNDING.yml"
104
161
  - ".gitignore"
162
+ - ".rubocop.yml"
105
163
  - ".travis.yml"
106
164
  - CODE_OF_CONDUCT.md
107
165
  - Gemfile
@@ -116,7 +174,7 @@ homepage: https://github.com/fnando/i18n-dot_lookup
116
174
  licenses:
117
175
  - MIT
118
176
  metadata: {}
119
- post_install_message:
177
+ post_install_message:
120
178
  rdoc_options: []
121
179
  require_paths:
122
180
  - lib
@@ -124,16 +182,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
182
  requirements:
125
183
  - - ">="
126
184
  - !ruby/object:Gem::Version
127
- version: '0'
185
+ version: 2.5.0
128
186
  required_rubygems_version: !ruby/object:Gem::Requirement
129
187
  requirements:
130
188
  - - ">="
131
189
  - !ruby/object:Gem::Version
132
190
  version: '0'
133
191
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.4.6
136
- signing_key:
192
+ rubygems_version: 3.1.2
193
+ signing_key:
137
194
  specification_version: 4
138
195
  summary: Allow interpolation to be performed on a object's attribute, e.g. %{user.name}
139
196
  test_files: []