seielit-i18n_goodies 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +161 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/i18n_goodies.gemspec +37 -0
- data/lib/i18n_goodies.rb +7 -0
- data/lib/seiel/i18n_goodies.rb +201 -0
- data/lib/seiel/i18n_goodies/version.rb +5 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0553dd6b51e099552dc8b165f9e788938c2804ac
|
4
|
+
data.tar.gz: c28ddb22e000739585735ab1a14640966b9e61ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0860fa6c666dfb45b772a531c36d27a91b1a17b8956d9dd67c313bb400f0f0297b4813aca117a45ec51d56264ede755f920f45db36e897b6b4b9b2321670733
|
7
|
+
data.tar.gz: 02bfd99348c47ef73b9f6c0775c837c56d65660ae677bfff60f92bc8fc0d28362e085c0ed112557e3d8e96b7a19900276bde81798845409242f492ab1aa84308
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
Exclude:
|
6
|
+
- '**/tmp/**/*'
|
7
|
+
- '**/script/**/*'
|
8
|
+
- Rakefile
|
9
|
+
- Gemfile
|
10
|
+
UseCache: true
|
11
|
+
TargetRubyVersion: 2.6
|
12
|
+
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Max: 20
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 20
|
18
|
+
|
19
|
+
Style/AsciiComments:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Layout/AlignArguments:
|
23
|
+
EnforcedStyle: with_fixed_indentation
|
24
|
+
IndentationWidth: 2
|
25
|
+
|
26
|
+
Lint/MissingCopEnableDirective:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/SymbolArray:
|
30
|
+
Enabled: true
|
31
|
+
MinSize: 4
|
32
|
+
|
33
|
+
StringLiterals:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
FormatString:
|
37
|
+
EnforcedStyle: percent
|
38
|
+
|
39
|
+
MultilineOperationIndentation:
|
40
|
+
EnforcedStyle: indented
|
41
|
+
|
42
|
+
MultilineMethodCallIndentation:
|
43
|
+
EnforcedStyle: indented
|
44
|
+
|
45
|
+
RedundantSelf:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
EmptyLinesAroundAccessModifier:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
LineLength:
|
52
|
+
Max: 110
|
53
|
+
|
54
|
+
MethodLength:
|
55
|
+
Max: 35
|
56
|
+
|
57
|
+
EndAlignment:
|
58
|
+
EnforcedStyleAlignWith: variable
|
59
|
+
|
60
|
+
PerceivedComplexity:
|
61
|
+
Max: 7
|
62
|
+
|
63
|
+
BlockDelimiters:
|
64
|
+
EnforcedStyle: semantic
|
65
|
+
FunctionalMethods:
|
66
|
+
- let
|
67
|
+
- let!
|
68
|
+
- html
|
69
|
+
- git_source
|
70
|
+
- json
|
71
|
+
- map
|
72
|
+
- map!
|
73
|
+
- modal
|
74
|
+
- reject!
|
75
|
+
- select!
|
76
|
+
- sequence
|
77
|
+
- specify
|
78
|
+
- subject
|
79
|
+
- watch
|
80
|
+
ProceduralMethods:
|
81
|
+
- build
|
82
|
+
- content_tag
|
83
|
+
- each
|
84
|
+
- find_or_initialize_by
|
85
|
+
- find_or_create_by
|
86
|
+
- new
|
87
|
+
- tag
|
88
|
+
- tap
|
89
|
+
|
90
|
+
AlignParameters:
|
91
|
+
EnforcedStyle: with_fixed_indentation
|
92
|
+
|
93
|
+
CollectionMethods:
|
94
|
+
PreferredMethods:
|
95
|
+
inject: 'reduce'
|
96
|
+
detect: 'detect'
|
97
|
+
|
98
|
+
ArrayJoin:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
# AlignHash:
|
102
|
+
# EnforcedColonStyle: key
|
103
|
+
|
104
|
+
CommentAnnotation:
|
105
|
+
Keywords:
|
106
|
+
- DRYME
|
107
|
+
- FIXME
|
108
|
+
- HACK
|
109
|
+
- HACKAROUND
|
110
|
+
- OPTIMIZE
|
111
|
+
- OPTIMIZEME
|
112
|
+
- REVIEW
|
113
|
+
- TBD
|
114
|
+
- TODO
|
115
|
+
- WORKAROUND
|
116
|
+
|
117
|
+
DotPosition:
|
118
|
+
EnforcedStyle: trailing
|
119
|
+
|
120
|
+
Lambda:
|
121
|
+
Enabled: false
|
122
|
+
|
123
|
+
AlignHash:
|
124
|
+
EnforcedLastArgumentHashStyle: ignore_implicit
|
125
|
+
|
126
|
+
ClassLength:
|
127
|
+
Max: 160
|
128
|
+
|
129
|
+
CaseIndentation:
|
130
|
+
EnforcedStyle: end
|
131
|
+
IndentOneStep: false
|
132
|
+
|
133
|
+
# improve in a newer version
|
134
|
+
AbcSize:
|
135
|
+
Max: 27
|
136
|
+
|
137
|
+
RegexpLiteral:
|
138
|
+
EnforcedStyle: mixed
|
139
|
+
AllowInnerSlashes: false
|
140
|
+
|
141
|
+
AsciiComments:
|
142
|
+
Enabled: false
|
143
|
+
|
144
|
+
ParameterLists:
|
145
|
+
CountKeywordArgs: false
|
146
|
+
|
147
|
+
Performance/Casecmp:
|
148
|
+
Enabled: false
|
149
|
+
|
150
|
+
Style/EmptyCaseCondition:
|
151
|
+
Enabled: false
|
152
|
+
|
153
|
+
Lint/NonLocalExitFromIterator:
|
154
|
+
Enabled: false
|
155
|
+
|
156
|
+
Documentation:
|
157
|
+
Enabled: false
|
158
|
+
|
159
|
+
Metrics/BlockLength:
|
160
|
+
Exclude:
|
161
|
+
- '**/*.axlsx'
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [1.0.0] - 2017-06-20
|
11
|
+
|
12
|
+
* extracted from AIEPBA Comenius
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at icarrera@seiel.com.ar. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
seielit-i18n_goodies (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 2.0)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
seielit-i18n_goodies!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ignacio Carrera
|
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,55 @@
|
|
1
|
+
# I18nGoodies
|
2
|
+
|
3
|
+
Adds convenience methods to ActiveRecord models.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'i18n_goodies',
|
11
|
+
git: 'https://code.seiel.com.ar/seiel/i18n_goodies',
|
12
|
+
ref: 'v1.0.0'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
…
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ gem install i18n_goodies
|
26
|
+
…
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
In your `application_model.rb`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
include Seiel::I18nGoodies
|
35
|
+
```
|
36
|
+
|
37
|
+
TODO: specify each method.
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
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
|
+
|
43
|
+
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).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/[USERNAME]/i18n_goodies.> 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.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
52
|
+
|
53
|
+
## Code of Conduct
|
54
|
+
|
55
|
+
Everyone interacting in the I18nGoodies project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/i18n_goodies/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "i18n_goodies"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'seiel/i18n_goodies/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'seielit-i18n_goodies'
|
10
|
+
spec.version = I18nGoodies::VERSION
|
11
|
+
spec.authors = ['Ignacio Carrera']
|
12
|
+
spec.email = ['icarrera@seiel.com.ar']
|
13
|
+
|
14
|
+
spec.summary = 'Adds convenience methods to ActiveRecord models.'
|
15
|
+
spec.homepage = 'https://code.seiel.com.ar/seiel/i18n_goodies'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do # rubocop:disable ExpandPathArguments
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = 'bin'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler',
|
32
|
+
'~> 2.0'
|
33
|
+
spec.add_development_dependency 'minitest',
|
34
|
+
'~> 5.0'
|
35
|
+
spec.add_development_dependency 'rake',
|
36
|
+
'~> 10.0'
|
37
|
+
end
|
data/lib/i18n_goodies.rb
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seiel
|
4
|
+
# Extend Rails' #i18n_scope method to return the long path for i18n scopes
|
5
|
+
module I18nGoodies
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
extend ClassMethods
|
10
|
+
extend Enums
|
11
|
+
end
|
12
|
+
|
13
|
+
def i18n_scope(*args)
|
14
|
+
self.class.i18n_scope(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def i18n(key, *args, **kws)
|
18
|
+
key = send(key) if key.is_a? Symbol
|
19
|
+
|
20
|
+
self.class.i18n(key, *args, **kws)
|
21
|
+
end
|
22
|
+
|
23
|
+
def error_message(key, data = {})
|
24
|
+
i18n key.to_s, :errors, :messages, data, model: true
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def i18n_scope(*args)
|
29
|
+
if args.empty?
|
30
|
+
super
|
31
|
+
else
|
32
|
+
opts = args.extract_options!
|
33
|
+
(
|
34
|
+
[
|
35
|
+
super(),
|
36
|
+
args.shift,
|
37
|
+
(opts[:skip_models] ? nil : :models),
|
38
|
+
model_name.i18n_key
|
39
|
+
].compact + args.compact
|
40
|
+
).map(&:to_s)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def i18n(key, *args, **kws)
|
45
|
+
if kws[:model]
|
46
|
+
kws[:skip_models] = false
|
47
|
+
kws[:skip_enums] = true
|
48
|
+
end
|
49
|
+
|
50
|
+
kws[:skip_models] = true unless kws.key?(:skip_models)
|
51
|
+
skip_enums = kws.delete(:skip_enums)
|
52
|
+
|
53
|
+
args.unshift :enums unless skip_enums
|
54
|
+
|
55
|
+
data = {}
|
56
|
+
data.merge! args.pop if args.last.is_a?(Hash)
|
57
|
+
data[:scope] = i18n_scope(*args, **kws)
|
58
|
+
|
59
|
+
I18n.t key,
|
60
|
+
data
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Adapts enums with i18n conventions for statuses
|
65
|
+
#
|
66
|
+
# @param [Hash] definitions Same as Rails' own
|
67
|
+
#
|
68
|
+
def status_enum(definitions)
|
69
|
+
enum definitions,
|
70
|
+
namespace: :statuses,
|
71
|
+
namespace_skip_models: false,
|
72
|
+
default_kind: :captions
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Decorate Rails' #enum with i18n methods.
|
77
|
+
#
|
78
|
+
# * `Model.plural_enums.i18n`: returns an array of arrays like `['Caption', 'string', 0]`
|
79
|
+
# * `Model.plural_enums.for_select`: returns an array useful for an html select
|
80
|
+
#
|
81
|
+
# @param [Hash] definitions Same as Rails' own
|
82
|
+
# @param [#to_s] namespace: useful for i18n scopes; default :enums
|
83
|
+
# @param [bool] namespace_skip_models: useful for i18n scopes; default true
|
84
|
+
# @param [#to_s] default_kind: useful for i18n scopes; default nil
|
85
|
+
#
|
86
|
+
def enum(definitions, namespace: :enums, namespace_skip_models: true, default_kind: nil)
|
87
|
+
super(definitions)
|
88
|
+
|
89
|
+
klass = self
|
90
|
+
definitions.each do |name, _|
|
91
|
+
meth = name.to_s.pluralize
|
92
|
+
feature = 'i18n_extensions'
|
93
|
+
with = "#{meth}_with_#{feature}"
|
94
|
+
without = "#{meth}_without_#{feature}"
|
95
|
+
klass.singleton_class.send(:define_method, with) {
|
96
|
+
value = send(without).try :dup
|
97
|
+
|
98
|
+
unless value.nil?
|
99
|
+
value.extend Enums::ClassExtensions
|
100
|
+
value._model = self
|
101
|
+
value._enum = name
|
102
|
+
value._namespace = namespace
|
103
|
+
value._namespace_skip_models = namespace_skip_models
|
104
|
+
value._default_kind = default_kind
|
105
|
+
value
|
106
|
+
end
|
107
|
+
}
|
108
|
+
|
109
|
+
# FIXME: buscar la manera de utilizar #prepend
|
110
|
+
eigenclass = klass.singleton_class
|
111
|
+
eigenclass.send(:alias_method, without, meth)
|
112
|
+
eigenclass.send(:alias_method, meth, with)
|
113
|
+
|
114
|
+
define_method(name) {
|
115
|
+
value = super().try :dup
|
116
|
+
|
117
|
+
unless value.nil?
|
118
|
+
value.extend Enums::Extensions
|
119
|
+
value._model = self
|
120
|
+
value._enum = name
|
121
|
+
value._namespace = namespace
|
122
|
+
value._namespace_skip_models = namespace_skip_models
|
123
|
+
value._default_kind = default_kind
|
124
|
+
value
|
125
|
+
end
|
126
|
+
}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Extend ActiveRecord's #enum to extend values with i18n helpers
|
132
|
+
module Enums
|
133
|
+
module Extensions
|
134
|
+
attr_accessor :_model,
|
135
|
+
:_enum,
|
136
|
+
:_namespace,
|
137
|
+
:_namespace_skip_models,
|
138
|
+
:_default_kind
|
139
|
+
|
140
|
+
def i18n(kind = nil, **kws)
|
141
|
+
kind ||= _default_kind
|
142
|
+
kws[:scope] = _model.i18n_scope _namespace,
|
143
|
+
kind,
|
144
|
+
_enum,
|
145
|
+
skip_models: _namespace_skip_models
|
146
|
+
|
147
|
+
I18n.t self,
|
148
|
+
kws
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
module ClassExtensions
|
153
|
+
attr_accessor :_model,
|
154
|
+
:_enum,
|
155
|
+
:_namespace,
|
156
|
+
:_namespace_skip_models,
|
157
|
+
:_default_kind
|
158
|
+
|
159
|
+
def i18n(kind = nil)
|
160
|
+
kind ||= _default_kind
|
161
|
+
map { |code, id|
|
162
|
+
[
|
163
|
+
I18n.t(
|
164
|
+
code,
|
165
|
+
scope: _model.i18n_scope(_namespace, kind, _enum, skip_models: _namespace_skip_models)
|
166
|
+
),
|
167
|
+
code,
|
168
|
+
id
|
169
|
+
]
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
def for_select(kind = nil)
|
174
|
+
kind ||= _default_kind
|
175
|
+
|
176
|
+
map { |code, _|
|
177
|
+
data = %i[classes iconos captions].map { |key|
|
178
|
+
{
|
179
|
+
key => I18n.t(
|
180
|
+
code,
|
181
|
+
scope: _model.i18n_scope(_namespace, key, _enum, skip_models: _namespace_skip_models),
|
182
|
+
default: ''
|
183
|
+
)
|
184
|
+
}
|
185
|
+
}.reduce(:merge)
|
186
|
+
data.reject! { |_, str| str.blank? }
|
187
|
+
|
188
|
+
[
|
189
|
+
I18n.t(
|
190
|
+
code,
|
191
|
+
scope: _model.i18n_scope(_namespace, kind, _enum, skip_models: _namespace_skip_models)
|
192
|
+
),
|
193
|
+
code,
|
194
|
+
data
|
195
|
+
].compact
|
196
|
+
}
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seielit-i18n_goodies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ignacio Carrera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- icarrera@seiel.com.ar
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- i18n_goodies.gemspec
|
75
|
+
- lib/i18n_goodies.rb
|
76
|
+
- lib/seiel/i18n_goodies.rb
|
77
|
+
- lib/seiel/i18n_goodies/version.rb
|
78
|
+
homepage: https://code.seiel.com.ar/seiel/i18n_goodies
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata:
|
82
|
+
homepage_uri: https://code.seiel.com.ar/seiel/i18n_goodies
|
83
|
+
source_code_uri: https://code.seiel.com.ar/seiel/i18n_goodies
|
84
|
+
changelog_uri: https://code.seiel.com.ar/seiel/i18n_goodies
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.6.8
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Adds convenience methods to ActiveRecord models.
|
105
|
+
test_files: []
|