enum_translatable 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cd16932b5577e7f652b6bd3df5ec1a4c33887fee194e645b9afad50056f05cc5
4
+ data.tar.gz: 4727e1bcef752b1ca495fab4c942b4ebf0d51569af7a0af2c748515e2ee00d11
5
+ SHA512:
6
+ metadata.gz: d2aedc8343a18e9ba28b492b165b8330cc0ca55d457e8320dd1e3b731632ace316ba49f154ac0eb2275a5e657465b359da33ad14c5f1fdd6f49a05f1a7a0abb6
7
+ data.tar.gz: 7d6126dbfa7fa8672dc428503284c33c88014744745e60708cf172555045f78e8ab586a0f433759e3d7c985f78b895a4c659c02edd65b88b557321fbbddc04d1
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.8
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in enum_translatable.gemspec
4
+ gemspec
5
+
6
+ gem "rake", ">= 0.8.7"
7
+ gem "rspec", ">= 3.0"
8
+ gem 'globalize', '~> 5.3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ enum_translatable (0.1.3)
5
+ globalize
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.0.3.4)
11
+ activesupport (= 6.0.3.4)
12
+ activerecord (6.0.3.4)
13
+ activemodel (= 6.0.3.4)
14
+ activesupport (= 6.0.3.4)
15
+ activesupport (6.0.3.4)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2, >= 2.2.2)
21
+ concurrent-ruby (1.1.7)
22
+ diff-lcs (1.4.4)
23
+ globalize (5.3.0)
24
+ activemodel (>= 4.2, < 6.1)
25
+ activerecord (>= 4.2, < 6.1)
26
+ request_store (~> 1.0)
27
+ i18n (1.8.7)
28
+ concurrent-ruby (~> 1.0)
29
+ minitest (5.14.3)
30
+ rack (2.2.3)
31
+ rake (13.0.3)
32
+ request_store (1.5.0)
33
+ rack (>= 1.4)
34
+ rspec (3.10.0)
35
+ rspec-core (~> 3.10.0)
36
+ rspec-expectations (~> 3.10.0)
37
+ rspec-mocks (~> 3.10.0)
38
+ rspec-core (3.10.1)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-expectations (3.10.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-mocks (3.10.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-support (3.10.1)
47
+ thread_safe (0.3.6)
48
+ tzinfo (1.2.9)
49
+ thread_safe (~> 0.1)
50
+ zeitwerk (2.4.2)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ enum_translatable!
57
+ globalize (~> 5.3.0)
58
+ rake (>= 0.8.7)
59
+ rspec (>= 3.0)
60
+
61
+ BUNDLED WITH
62
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 mohamedmmahfouz
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,114 @@
1
+ # EnumTranslatable
2
+
3
+ A simple Gem that translates ruby on rails enums in a similar manner to I18n globalize gem.
4
+
5
+ ## Installation
6
+ Make sure you add globalize gem https://github.com/globalize/globalize
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'enum_translatable', '~> 0.1.1'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install enum_translatable
21
+
22
+ ## Usage
23
+
24
+
25
+ The Gem will some methods into your selected model similar to what globalize gem adds to a translated field.
26
+ for example if we have the following class
27
+ ````ruby
28
+ class Order < ApplicationRecord
29
+ enum status:{
30
+ pending: 0,
31
+ canceled: 1,
32
+ approved: 2,
33
+ }
34
+ end
35
+ ````
36
+
37
+ by adding the following
38
+ ````ruby
39
+ class Order < ApplicationRecord
40
+ enum status:{
41
+ pending: 0,
42
+ canceled: 1,
43
+ approved: 2,
44
+ }
45
+ include EnumTranslatable ##this has to be added after the last enum defined in your model which needs to be translated
46
+ #Note: Adding this line will translate ALL the enums defined above it.
47
+ end
48
+ ````
49
+ Then adding the translations in your local.yml
50
+ ````yml
51
+ #en.yml
52
+ en:
53
+ activerecord:
54
+ enum_translatable:
55
+ order:
56
+ status:
57
+ canceled: "canceled"
58
+ pending: "pending"
59
+ approved: "approved"
60
+ ````
61
+ ````yml
62
+ #ar.yml
63
+ ar:
64
+ activerecord:
65
+ enum_translatable:
66
+ order:
67
+ status:
68
+ canceled: "canceled in arabic"
69
+ pending: "pending in arabic"
70
+ approved: "approved in arabic"
71
+ ````
72
+ ````yml
73
+ #es.yml
74
+ es:
75
+ activerecord:
76
+ enum_translatable:
77
+ order:
78
+ status:
79
+ canceled: "canceled in spanish"
80
+ pending: "pending in spanish"
81
+ approved: "approved in spanish"
82
+ ````
83
+ it will add the following methods
84
+
85
+ ````ruby
86
+ order = Order.first
87
+ order.status # => "canceled"
88
+ order.translated_status # => "canceled"
89
+ order.status_en # => "canceled"
90
+ order.status_ar # => "canceled in arabic"
91
+ order.status_es # => "canceled in spanish"
92
+ I18.locale = :ar
93
+ Order.translated_status = "canceled in arabic"
94
+ ````
95
+
96
+ Make sure to add the locales you want to use, other wise you will have a method for each I18n locale which is unecessary
97
+ ````ruby
98
+ # in config/initializer/locale.rb
99
+ I18n.available_locales = [:ar, :es, :en]
100
+ ````
101
+ ## Development
102
+
103
+ 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.
104
+
105
+ 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).
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enum_translatable.
110
+
111
+
112
+ ## License
113
+
114
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enum_translatable"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
Binary file
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/enum_translatable/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "enum_translatable"
5
+ spec.version = EnumTranslatable::VERSION
6
+ spec.authors = ["mohamedmmahfouz"]
7
+ spec.email = ["mohamedmmahfouz24@gmail.com"]
8
+
9
+ spec.summary = %q{Gem for translating enums with i18n.}
10
+ spec.description = %q{ROR gem which to translate enums just like I18n Globalize gem}
11
+ spec.homepage = "https://github.com/MohamedMMahfouz/enum_translatable"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ # spec.metadata["source_code_uri"] = "https://github.com/MohamedMMahfouz/enum_translatable"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.add_runtime_dependency "globalize"
28
+ end
@@ -0,0 +1,24 @@
1
+ require "enum_translatable/version"
2
+ require 'active_support/concern'
3
+
4
+ module EnumTranslatable
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ defined_enums.keys.each do |key|
9
+ define_method :"#{key}" do
10
+ enum_value = self[:"#{key}"]
11
+ return nil unless enum_value.present?
12
+ I18n.t("activerecord.enum_translatable.#{model_name.singular}.#{key}.#{enum_value}", default: enum_value)
13
+ end
14
+
15
+ I18n.available_locales.each do |locale|
16
+ define_method :"#{key}_#{locale}" do
17
+ I18n.with_locale(locale) do
18
+ send("#{key}")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module EnumTranslatable
2
+ VERSION = "0.1.3"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enum_translatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - mohamedmmahfouz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: globalize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ description: ROR gem which to translate enums just like I18n Globalize gem
28
+ email:
29
+ - mohamedmmahfouz24@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - enum_translatable-0.1.1.gem
45
+ - enum_translatable-0.1.2.gem
46
+ - enum_translatable.gemspec
47
+ - lib/enum_translatable.rb
48
+ - lib/enum_translatable/version.rb
49
+ homepage: https://github.com/MohamedMMahfouz/enum_translatable
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/MohamedMMahfouz/enum_translatable
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.7.6.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Gem for translating enums with i18n.
74
+ test_files: []