locales_toys 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ec83c44fbfddb91c0211aa00aeede56dbdde3f229ffb7c6115bac89ae382d1c4
4
+ data.tar.gz: 86932a0f79eedf6bdd7d74f25642e8d09b347a205d269a3cc45d0314810a55d8
5
+ SHA512:
6
+ metadata.gz: e29bcc0ec47333887636d30b2c55d776220c2e8bc964c40876eae0f5d39b2e657100a60ab300f4c2aaf73ffc685ffcc25da9d0a673e5a2a90a76259af607e7b2
7
+ data.tar.gz: 61376e634f19f9fc7632e6867541e736a0de3911d8af170804f434abc0de0f0ff8eecfd508bf3f96ed6dc7f41d80a50d81a231e3e8c444ede8d35f2a882cb68a
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## master (unreleased)
4
+
5
+ ## 0.1.0 (2020-07-13)
6
+
7
+ * Initial release.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alexander Popov
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.
@@ -0,0 +1,58 @@
1
+ # Locales Toys
2
+
3
+ [![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/locales_toys?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/locales_toys)
4
+ [![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/locales_toys/master.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/locales_toys)
5
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/locales_toys.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/locales_toys)
6
+ [![Depfu](https://img.shields.io/depfu/AlexWayfer/benchmark_toys?style=flat-square)](https://depfu.com/repos/github/AlexWayfer/locales_toys)
7
+ [![Inline docs](https://inch-ci.org/github/AlexWayfer/locales_toys.svg?branch=master)](https://inch-ci.org/github/AlexWayfer/locales_toys)
8
+ [![license](https://img.shields.io/github/license/AlexWayfer/locales_toys.svg?style=flat-square)](https://github.com/AlexWayfer/locales_toys/blob/master/LICENSE.txt)
9
+ [![Gem](https://img.shields.io/gem/v/locales_toys.svg?style=flat-square)](https://rubygems.org/gems/locales_toys)
10
+
11
+ Toys template for locales, for example, [R18n](https://github.com/r18n/r18n).
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'locales_toys'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```shell
24
+ bundle install
25
+ ```
26
+
27
+ Or install it yourself as:
28
+
29
+ ```shell
30
+ gem install locales_toys
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```ruby
36
+ require 'locales_toys'
37
+ expand LocalesToys::Template
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bundle install` to install dependencies.
43
+
44
+ Then, run `toys rspec` to run the tests.
45
+
46
+ To install this gem onto your local machine, run `toys gem install`.
47
+
48
+ To release a new version, run `toys gem release %version%`.
49
+ See how it works [here](https://github.com/AlexWayfer/gem_toys#release).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/locales_toys).
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the
58
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'locales_toys/template'
4
+ require_relative 'locales_toys/version'
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'toys-core'
4
+
5
+ require_relative 'template/locale'
6
+
7
+ module LocalesToys
8
+ ## Define toys for locales
9
+ class Template
10
+ include Toys::Template
11
+
12
+ on_expand do
13
+ tool :locales do
14
+ tool :check do
15
+ desc 'Check locales'
16
+
17
+ def run
18
+ require 'yaml'
19
+ require 'json'
20
+
21
+ locales = Locale.load(context_directory)
22
+
23
+ locales.each_with_index do |locale, ind|
24
+ locales[ind..-1].each do |other_locale|
25
+ next if locale == other_locale
26
+
27
+ compare_locales(locale, other_locale)
28
+ compare_locales(other_locale, locale)
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def compare_locales(locale, other_locale)
36
+ puts "#{locale.code.upcase} -> #{other_locale.code.upcase}:\n\n"
37
+ puts locale.diff(other_locale).to_yaml
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ ## Class for Locale file
6
+ class Locale
7
+ attr_reader :code, :hash
8
+
9
+ def self.load(context_directory)
10
+ Dir["#{context_directory}/locales/*.y{a,}ml"].map do |file|
11
+ new File.basename(file, '.*'), YAML.load_file(file) || {}
12
+ end
13
+ end
14
+
15
+ def initialize(code, hash)
16
+ @code = code
17
+ @hash = hash
18
+ end
19
+
20
+ ## Compares generic values and returns rich diff
21
+ class HashCompare
22
+ def initialize(hash, other_hash)
23
+ @hash = hash
24
+ @other_hash = other_hash
25
+ end
26
+
27
+ def different_keys
28
+ @hash.each_with_object({}) do |(key, value), result|
29
+ difference = generic_difference(value, @other_hash[key])
30
+ next if difference.nil? || difference.empty?
31
+
32
+ result[key] = difference
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def generic_difference(value, other_value)
39
+ return value if value.class != other_value.class
40
+
41
+ case value
42
+ when Hash
43
+ self.class.new(value, other_value).different_keys
44
+ when Array
45
+ differences_in_array(value, other_value)
46
+ when nil
47
+ value
48
+ end
49
+ end
50
+
51
+ def differences_in_array(array, other_array)
52
+ return array if array.size != other_array.size
53
+
54
+ array.zip(other_array).map do |object, other_object|
55
+ next if !object.is_a?(Hash) || !other_object.is_a?(Hash)
56
+
57
+ difference = self.class.new(object, other_object).different_keys
58
+ difference unless difference.empty?
59
+ end.compact
60
+ end
61
+ end
62
+
63
+ def diff(other)
64
+ HashCompare.new(hash, other.hash).different_keys
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LocalesToys
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locales_toys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Popov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: toys-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gem_toys
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: toys
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: codecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.18.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.18.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.88.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.88.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-performance
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.0'
167
+ description: 'Toys template for locales.
168
+
169
+ '
170
+ email:
171
+ - alex.wayfer@gmail.com
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - CHANGELOG.md
177
+ - LICENSE.txt
178
+ - README.md
179
+ - lib/locales_toys.rb
180
+ - lib/locales_toys/template.rb
181
+ - lib/locales_toys/template/locale.rb
182
+ - lib/locales_toys/version.rb
183
+ homepage: https://github.com/AlexWayfer/locales_toys
184
+ licenses:
185
+ - MIT
186
+ metadata:
187
+ source_code_uri: https://github.com/AlexWayfer/locales_toys
188
+ homepage_uri: https://github.com/AlexWayfer/locales_toys
189
+ changelog_uri: https://github.com/AlexWayfer/locales_toys/blob/master/CHANGELOG.md
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '2.5'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubygems_version: 3.1.2
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: Toys template for locales.
209
+ test_files: []