buddy_translatable 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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +21 -0
- data/README.md +167 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/buddy_translatable.gemspec +39 -0
- data/lib/buddy_translatable.rb +14 -0
- data/lib/buddy_translatable/configuration.rb +15 -0
- data/lib/buddy_translatable/core.rb +82 -0
- data/lib/buddy_translatable/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c27f8d71a4a6a67dcd1883d54e96031cac1675ac1ae880f4a47eece86f59e076
|
4
|
+
data.tar.gz: 1b88ce42d87729ecf590f851bbc4ede2c0dec4a883fc0e6b09cd24a82ae4cff0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9353bd3551054a978b2b9a56ca63f55252f655112995b2f919269f385420e02abf16d66ed397efabcb1f1d10eec3e88f0b037a7d544718cfebb944b46527b92
|
7
|
+
data.tar.gz: 5d9e36cff5af21f0fc1bb926247b0e7831d535dc0e5536e0dbff3cd670617f6146f46d9b6fe931280416f978b30f3b76c88e4e429e0320ece39cafe54dcc20fa
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
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 owenperedo@gmail.com. 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,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
buddy_translatable (0.1.0)
|
5
|
+
activerecord (>= 5.0)
|
6
|
+
activesupport (>= 5.0)
|
7
|
+
i18n
|
8
|
+
pg
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activemodel (5.2.3)
|
14
|
+
activesupport (= 5.2.3)
|
15
|
+
activerecord (5.2.3)
|
16
|
+
activemodel (= 5.2.3)
|
17
|
+
activesupport (= 5.2.3)
|
18
|
+
arel (>= 9.0)
|
19
|
+
activesupport (5.2.3)
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
i18n (>= 0.7, < 2)
|
22
|
+
minitest (~> 5.1)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
arel (9.0.0)
|
25
|
+
concurrent-ruby (1.1.5)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
i18n (1.6.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
minitest (5.11.3)
|
30
|
+
pg (1.1.4)
|
31
|
+
rake (10.5.0)
|
32
|
+
rspec (3.8.0)
|
33
|
+
rspec-core (~> 3.8.0)
|
34
|
+
rspec-expectations (~> 3.8.0)
|
35
|
+
rspec-mocks (~> 3.8.0)
|
36
|
+
rspec-core (3.8.2)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-expectations (3.8.4)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.8.0)
|
41
|
+
rspec-mocks (3.8.1)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.8.0)
|
44
|
+
rspec-support (3.8.2)
|
45
|
+
thread_safe (0.3.6)
|
46
|
+
tzinfo (1.2.5)
|
47
|
+
thread_safe (~> 0.1)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
buddy_translatable!
|
54
|
+
bundler
|
55
|
+
rake (~> 10.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Owen
|
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,167 @@
|
|
1
|
+
# JSON Buddy Translatable
|
2
|
+
|
3
|
+
Allows you to store text data in multiple languages or Sales channels. Based on [translateable](https://github.com/olegantonyan/translateable), but with a few differences:
|
4
|
+
|
5
|
+
1. Support for key methods
|
6
|
+
2. Support for Sales channels
|
7
|
+
|
8
|
+
### Translations
|
9
|
+
```ruby
|
10
|
+
class Post < ActiveRecord::Base
|
11
|
+
include BuddyTranslatable
|
12
|
+
translatable :title, default_key: :de
|
13
|
+
end
|
14
|
+
|
15
|
+
post = Post.create(title: { de: 'Hallo', en: 'Hello' })
|
16
|
+
|
17
|
+
# getter using current locale
|
18
|
+
I18n.locale = :en
|
19
|
+
post.title #=> Hello
|
20
|
+
I18n.locale = :de
|
21
|
+
post.title #=> Hallo
|
22
|
+
|
23
|
+
# Getter using methods
|
24
|
+
post.title_en #=> Hello
|
25
|
+
post.title_de #=> Hallo
|
26
|
+
post.title_data_for(:en) #=> Hello
|
27
|
+
post.title_data # => return all data (Hash)
|
28
|
+
|
29
|
+
# Update current locale and maintain others
|
30
|
+
I18n.locale = :en
|
31
|
+
post.update(title: 'Hello changed')
|
32
|
+
post.title_en # => Hello changed
|
33
|
+
post.title_de # => Hallo
|
34
|
+
post.title_es # => Hallo (return default key if not found)
|
35
|
+
|
36
|
+
# Replace all data
|
37
|
+
post.update(title: { en: 'En val', de: 'De val' })
|
38
|
+
post.title_en # => En val
|
39
|
+
```
|
40
|
+
|
41
|
+
### Sales Channels
|
42
|
+
```ruby
|
43
|
+
class Post < ActiveRecord::Base
|
44
|
+
include BuddyTranslatable
|
45
|
+
sales_datable :key, default_key: :vev
|
46
|
+
end
|
47
|
+
post = Post.create(key: { vev: 'vev', ebay: 'ebay' })
|
48
|
+
|
49
|
+
# getter
|
50
|
+
post.key #=> vev # return default key
|
51
|
+
BuddyTranslatable.config.current_sales_key = :ebay
|
52
|
+
post.key #=> ebay
|
53
|
+
|
54
|
+
# you can reset current sales channel by
|
55
|
+
BuddyTranslatable.config.reset_current_sales_key
|
56
|
+
|
57
|
+
# Getter using methods
|
58
|
+
post.key_vev #=> vev
|
59
|
+
post.key_ebay #=> ebay
|
60
|
+
post.key_data_for(:vev) #=> vev
|
61
|
+
post.key_data # => return all data (Hash)
|
62
|
+
|
63
|
+
# Update current sales key (if empty will use default_key) and maintain others
|
64
|
+
BuddyTranslatable.config.current_sales_key = :ebay
|
65
|
+
post.update(key: 'Ebay changed')
|
66
|
+
post.key_ebay # => Ebay changed
|
67
|
+
post.key_vev # => vev
|
68
|
+
|
69
|
+
# Replace all data
|
70
|
+
post.update(key: { vev: 'vev val', ebay: 'ebay val' })
|
71
|
+
post.key_vev # => vev val
|
72
|
+
```
|
73
|
+
|
74
|
+
## Requirements
|
75
|
+
|
76
|
+
- PostgreSQL >= 9.4
|
77
|
+
- ActiveRecord >= 4.2
|
78
|
+
- I18n
|
79
|
+
|
80
|
+
## Installation
|
81
|
+
|
82
|
+
Add this line to your application's Gemfile:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
gem 'buddy_translatable'
|
86
|
+
```
|
87
|
+
|
88
|
+
Create initializer:
|
89
|
+
```ruby
|
90
|
+
# config/initializers/translatable.rb
|
91
|
+
BuddyTranslatable.config.available_sales_keys = %i[de ebay]
|
92
|
+
I18n.available_locales = %i[de en es]
|
93
|
+
```
|
94
|
+
|
95
|
+
And then execute:
|
96
|
+
``` bundle install ```
|
97
|
+
|
98
|
+
## Usage
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
class TestModel < ActiveRecord::Base
|
102
|
+
include BuddyTranslatable
|
103
|
+
|
104
|
+
translatable :title, default_key: :de
|
105
|
+
sales_datable :key, default_key: :vev #, available_keys: [:ebay, :amazon, :vev]
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
### Migration
|
110
|
+
|
111
|
+
Attributes must be `JSONB` type.
|
112
|
+
```ruby
|
113
|
+
class AddTitleToPosts < ActiveRecord::Migration
|
114
|
+
def change
|
115
|
+
add_column :posts, :title, :jsonb, null: false, default: {}
|
116
|
+
add_column :posts, :key, :jsonb, null: false, default: {}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
### Queries
|
122
|
+
|
123
|
+
For searching you can use the following concern:
|
124
|
+
```ruby
|
125
|
+
module JsonbQuerable
|
126
|
+
extend ActiveSupport::Concern
|
127
|
+
|
128
|
+
included do
|
129
|
+
scope :where_jsonb_value, lambda { |attr, value|
|
130
|
+
attr_query = sanitize_sql("#{table_name}.#{attr}")
|
131
|
+
where("EXISTS (SELECT 1 FROM jsonb_each_text(#{attr_query}) j
|
132
|
+
WHERE j.value = ?)", value)
|
133
|
+
}
|
134
|
+
|
135
|
+
scope :where_jsonb_value_like, lambda { |attr, value, case_sens = false|
|
136
|
+
attr_query = sanitize_sql("#{table_name}.#{attr}")
|
137
|
+
condition = case_sens ? 'j.value LIKE ?' : 'lower(j.value) LIKE lower(?)'
|
138
|
+
where("EXISTS (SELECT 1
|
139
|
+
FROM jsonb_each_text(#{attr_query}) j
|
140
|
+
WHERE #{condition})", "%#{value}%")
|
141
|
+
}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
class Post < ActiveRecord::Base
|
146
|
+
#...
|
147
|
+
include JsonbQuerable
|
148
|
+
#...
|
149
|
+
end
|
150
|
+
|
151
|
+
Post.where_jsonb_value_like(:key, 'ebay')
|
152
|
+
```
|
153
|
+
Simple queries:
|
154
|
+
```ruby
|
155
|
+
Post.where("title->>'en' = ?", 'hello')
|
156
|
+
```
|
157
|
+
|
158
|
+
## Development
|
159
|
+
|
160
|
+
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.
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/owen2345/buddy_translatable.
|
165
|
+
|
166
|
+
## License
|
167
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "buddy_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,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'buddy_translatable/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'buddy_translatable'
|
10
|
+
spec.version = BuddyTranslatable::VERSION
|
11
|
+
spec.authors = ['Owen']
|
12
|
+
spec.email = ['owenperedo@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = 'Manages translations and sales data fields'
|
15
|
+
spec.description = 'Manages translations and sales data fields'
|
16
|
+
spec.homepage = 'https://github.com/owen2345/buddy_translatable'
|
17
|
+
spec.license = 'MIT'
|
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
|
21
|
+
# into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^(test|spec|features)/})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = %w[lib]
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
|
35
|
+
spec.add_dependency 'activerecord', '>= 5.0'
|
36
|
+
spec.add_dependency 'activesupport', '>= 5.0'
|
37
|
+
spec.add_dependency 'i18n'
|
38
|
+
spec.add_dependency 'pg'
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'buddy_translatable/version'
|
4
|
+
require 'buddy_translatable/configuration'
|
5
|
+
require 'buddy_translatable/core'
|
6
|
+
module BuddyTranslatable
|
7
|
+
def self.config
|
8
|
+
@config ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend BuddyTranslatable::Core
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BuddyTranslatable
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :available_sales_keys, :current_sales_key
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@available_sales_keys = %i[vev ebay]
|
9
|
+
end
|
10
|
+
|
11
|
+
def reset_current_sales_key
|
12
|
+
@current_sales_key = nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BuddyTranslatable
|
4
|
+
module Core
|
5
|
+
def translatable(*attrs, default_key: :de, available_keys: [])
|
6
|
+
available_keys = I18n.available_locales unless available_keys.present?
|
7
|
+
attrs.each do |attr|
|
8
|
+
translatable_sanity_check(attr)
|
9
|
+
define_translatable_methods(attr, default_key)
|
10
|
+
define_translatable_key_methods(attr, available_keys)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def sales_datable(*attrs, default_key: :vev, available_keys: [])
|
15
|
+
unless available_keys.present?
|
16
|
+
available_keys = BuddyTranslatable.config.available_sales_keys
|
17
|
+
end
|
18
|
+
attrs.each do |attr|
|
19
|
+
translatable_sanity_check(attr)
|
20
|
+
define_translatable_methods(attr, default_key, is_locale: false)
|
21
|
+
define_translatable_key_methods(attr, available_keys)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def translatable_sanity_check(attr)
|
26
|
+
msg = "no such column '#{attr}' in '#{name}' model"
|
27
|
+
raise ArgumentError, msg unless column_names.include?(attr.to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def define_translatable_methods(attr, default_key, is_locale: true)
|
31
|
+
current_key = lambda do
|
32
|
+
res = I18n.locale
|
33
|
+
current_sales_key = BuddyTranslatable.config.current_sales_key
|
34
|
+
res = current_sales_key || default_key unless is_locale
|
35
|
+
res.to_sym
|
36
|
+
end
|
37
|
+
define_translatable_setters(attr, current_key)
|
38
|
+
define_translatable_key_getters(attr, default_key)
|
39
|
+
define_translatable_getters(attr, current_key)
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_translatable_setters(attr, current_key)
|
43
|
+
define_method("#{attr}_data=") do |arg|
|
44
|
+
data = send("#{attr}_data")
|
45
|
+
self[attr] = arg.is_a?(Hash) ? arg : data.merge(current_key.call => arg)
|
46
|
+
end
|
47
|
+
|
48
|
+
define_method("#{attr}=") do |arg|
|
49
|
+
send("#{attr}_data=", arg)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def define_translatable_key_getters(attr, default_key)
|
54
|
+
define_method("#{attr}_data_for") do |key|
|
55
|
+
value = send("#{attr}_data")
|
56
|
+
value[key] ||
|
57
|
+
value[default_key].presence ||
|
58
|
+
value.values.find(&:present?)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def define_translatable_getters(attr, current_key)
|
63
|
+
define_method("#{attr}_data") do
|
64
|
+
res = self[attr]
|
65
|
+
res = new_record? ? { current_key.call => '' } : {} unless res.present?
|
66
|
+
res.symbolize_keys.with_indifferent_access
|
67
|
+
end
|
68
|
+
|
69
|
+
define_method(attr) do |**_args|
|
70
|
+
send("#{attr}_data_for", current_key.call)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def define_translatable_key_methods(attr, keys)
|
75
|
+
keys.each do |key|
|
76
|
+
define_method("#{attr}_#{key}") do
|
77
|
+
send("#{attr}_data_for", key)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buddy_translatable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Owen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-19 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: i18n
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pg
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Manages translations and sales data fields
|
112
|
+
email:
|
113
|
+
- owenperedo@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- buddy_translatable.gemspec
|
130
|
+
- lib/buddy_translatable.rb
|
131
|
+
- lib/buddy_translatable/configuration.rb
|
132
|
+
- lib/buddy_translatable/core.rb
|
133
|
+
- lib/buddy_translatable/version.rb
|
134
|
+
homepage: https://github.com/owen2345/buddy_translatable
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.7.7
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Manages translations and sales data fields
|
158
|
+
test_files: []
|