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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61db17a047508f80e5a5d1e0c149efcea45ee59a1a2f06c6624a16691d49c6da
4
- data.tar.gz: 89c815eba978977f31f2404105075534a2311452a36f46a3c910f5362c491a69
3
+ metadata.gz: 471f370e4433b4fa1f6bed2cd889933a01a816de64b0954cf3cd71e0ef96a9c8
4
+ data.tar.gz: 4373f6df4f1b01ec917ac826c2bf6ab48ad52af66273c25ca9a653ff4902a15c
5
5
  SHA512:
6
- metadata.gz: eccbb1ed3369e12bf95a982153a40a4b018ebf2974c60c5464a910b108399b3902b6e9bba309d398fce303a8850f5a0ab1f6a0aa5f04d54669d99042e5a6ec63
7
- data.tar.gz: e0f7595d85aa395ee44884f908fb3badba42f2bd8c77bdfddc143e8b3b823cf23687f715446f551f18c50d00179aa985570129183061d599dee2fe2a627c5004
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
- ### Queries
93
+ ### Filters
94
94
 
95
- For searching you can use the following concern (Only `jsonb` format attributes):
95
+ - Filter for an item with exact value in any locale
96
96
  ```ruby
97
- module JsonbQuerable
98
- extend ActiveSupport::Concern
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
- Post.where_jsonb_value_like(:key, 'ebay')
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
- Simple queries:
106
+
107
+ - Filter for items where current locale has the exact provided value
126
108
  ```ruby
127
- Post.where("title->>'en' = ?", 'hello')
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
- BuddyTranslatable.parse_translatable_data(self[attr])
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BuddyTranslatable
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.2'
5
5
  end
@@ -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.0
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-02-12 00:00:00.000000000 Z
11
+ date: 2023-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler