buddy_translatable 1.1.0 → 1.1.2
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 +9 -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: 471f370e4433b4fa1f6bed2cd889933a01a816de64b0954cf3cd71e0ef96a9c8
|
4
|
+
data.tar.gz: 4373f6df4f1b01ec917ac826c2bf6ab48ad52af66273c25ca9a653ff4902a15c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a4a811c654de28648359b5c986a6528167e0297ef8a6337c76dce5c8ed42fd247a0895d999cb13f83a7530da20c48cc8d11939fcae5e94087f59e2dcc468bbd
|
7
|
+
data.tar.gz: 89891a8d35b481fbfb2e432977f65a246f13f51bfbf7c45255459dfc1d5fd6618293a61bbfb21e11c4ab0dcccb7956572eb84280144299bd9e8e9792920ec4b0
|
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
|
@@ -32,6 +32,11 @@ module BuddyTranslatable
|
|
32
32
|
define_method("#{attr}=") do |arg|
|
33
33
|
send("#{attr}_data=", arg)
|
34
34
|
end
|
35
|
+
|
36
|
+
# fixes "input shows original value when form.text_field" which uses value_before_type_cast
|
37
|
+
define_method "#{attr}_came_from_user?" do
|
38
|
+
false
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
# Sample:
|
@@ -55,7 +60,10 @@ module BuddyTranslatable
|
|
55
60
|
# model.title # print value for current locale
|
56
61
|
def define_translatable_getters(attr)
|
57
62
|
define_method("#{attr}_data") do
|
58
|
-
|
63
|
+
res = self[attr] || {}
|
64
|
+
res = new_record? ? { I18n.locale => '' } : {} unless res.present?
|
65
|
+
res = JSON.parse(res) if res.is_a?(String)
|
66
|
+
res.symbolize_keys
|
59
67
|
end
|
60
68
|
|
61
69
|
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.2
|
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-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|