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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61db17a047508f80e5a5d1e0c149efcea45ee59a1a2f06c6624a16691d49c6da
4
- data.tar.gz: 89c815eba978977f31f2404105075534a2311452a36f46a3c910f5362c491a69
3
+ metadata.gz: 14a66ca05f9355589a0a39d41e9432fc4f71bc52d7c6fbd686dfd941b1e867fb
4
+ data.tar.gz: e41a1b0f34843838a4dd6af3d6db262f721d97fdcf666f5419570b1c443f1829
5
5
  SHA512:
6
- metadata.gz: eccbb1ed3369e12bf95a982153a40a4b018ebf2974c60c5464a910b108399b3902b6e9bba309d398fce303a8850f5a0ab1f6a0aa5f04d54669d99042e5a6ec63
7
- data.tar.gz: e0f7595d85aa395ee44884f908fb3badba42f2bd8c77bdfddc143e8b3b823cf23687f715446f551f18c50d00179aa985570129183061d599dee2fe2a627c5004
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
- ### 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
@@ -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
- BuddyTranslatable.parse_translatable_data(self[attr])
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|
@@ -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.1'
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.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-02-12 00:00:00.000000000 Z
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler