buddy_translatable 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -30
- data/lib/buddy_translatable/core.rb +4 -1
- data/lib/buddy_translatable/version.rb +1 -1
- data/lib/buddy_translatable.rb +1 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14a66ca05f9355589a0a39d41e9432fc4f71bc52d7c6fbd686dfd941b1e867fb
|
4
|
+
data.tar.gz: e41a1b0f34843838a4dd6af3d6db262f721d97fdcf666f5419570b1c443f1829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6176e0b6865bc9c0eea329c6585536b2d6ac7ff0790201dac09aab63d72c1527575790f0dd4e7a5cf630b6702f3db3f6edaf942b6199bc3f5332bd611d698f
|
7
|
+
data.tar.gz: abecbd30c7f980eeafe4325a8ff9994a4700da8f8d8a45ffeb66a627266ab5a59db83cbfbd3401c5a2bad008578970eccc8127ec496790ff3eec58f1720af8c7
|
data/README.md
CHANGED
@@ -90,41 +90,24 @@ class AddTitleToPosts < ActiveRecord::Migration
|
|
90
90
|
end
|
91
91
|
```
|
92
92
|
|
93
|
-
###
|
93
|
+
### Filters
|
94
94
|
|
95
|
-
|
95
|
+
- Filter for an item with exact value in any locale
|
96
96
|
```ruby
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
included do
|
101
|
-
scope :where_jsonb_value, lambda { |attr, value|
|
102
|
-
attr_query = sanitize_sql("#{table_name}.#{attr}")
|
103
|
-
where("EXISTS (SELECT 1 FROM jsonb_each_text(#{attr_query}) j
|
104
|
-
WHERE j.value = ?)", value)
|
105
|
-
}
|
106
|
-
|
107
|
-
scope :where_jsonb_value_like, lambda { |attr, value, case_sens = false|
|
108
|
-
attr_query = sanitize_sql("#{table_name}.#{attr}")
|
109
|
-
condition = case_sens ? 'j.value LIKE ?' : 'lower(j.value) LIKE lower(?)'
|
110
|
-
where("EXISTS (SELECT 1
|
111
|
-
FROM jsonb_each_text(#{attr_query}) j
|
112
|
-
WHERE #{condition})", "%#{value}%")
|
113
|
-
}
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class Post < ActiveRecord::Base
|
118
|
-
#...
|
119
|
-
include JsonbQuerable
|
120
|
-
#...
|
121
|
-
end
|
97
|
+
# where_<attr_name>_with(value: String)
|
98
|
+
Post.where_key_with('ebay')
|
99
|
+
```
|
122
100
|
|
123
|
-
|
101
|
+
- Filter for items with any locale that contains the provided value
|
102
|
+
```ruby
|
103
|
+
# where_<attr_name>_like(value: String)
|
104
|
+
Post.where_key_like('bay')
|
124
105
|
```
|
125
|
-
|
106
|
+
|
107
|
+
- Filter for items where current locale has the exact provided value
|
126
108
|
```ruby
|
127
|
-
|
109
|
+
# where_<attr_name>_eq(value: String, locale?: Symbol)
|
110
|
+
Post.where_key_eq('ebay')
|
128
111
|
```
|
129
112
|
|
130
113
|
## Development
|
@@ -55,7 +55,10 @@ module BuddyTranslatable
|
|
55
55
|
# model.title # print value for current locale
|
56
56
|
def define_translatable_getters(attr)
|
57
57
|
define_method("#{attr}_data") do
|
58
|
-
|
58
|
+
res = self[attr] || {}
|
59
|
+
res = new_record? ? { I18n.locale => '' } : {} unless res.present?
|
60
|
+
res = JSON.parse(res) if res.is_a?(String)
|
61
|
+
res.symbolize_keys
|
59
62
|
end
|
60
63
|
|
61
64
|
define_method(attr) do |**_args|
|
data/lib/buddy_translatable.rb
CHANGED
@@ -7,15 +7,8 @@ module BuddyTranslatable
|
|
7
7
|
base.extend BuddyTranslatable::Core
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.parse_translatable_data(data)
|
11
|
-
res = data || {}
|
12
|
-
res = {} unless res.present?
|
13
|
-
res = JSON.parse(res) if res.is_a?(String)
|
14
|
-
res.symbolize_keys
|
15
|
-
end
|
16
|
-
|
17
10
|
def self.translatable_attr_json?(model_class, attr)
|
18
|
-
migrated = ActiveRecord::Base.connection.tables.include?(model_class.table_name)
|
11
|
+
migrated = ActiveRecord::Base.connection.tables.include?(model_class.table_name) rescue nil
|
19
12
|
return :text unless migrated
|
20
13
|
|
21
14
|
columns_data = model_class.try(:column_types) || model_class.try(:attribute_types)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buddy_translatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|