awesome_hstore_translate 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b7a102f4de133d326d96a0b697f2c546409ce88
4
- data.tar.gz: 032d0828417f873bb3b4772fb4da311baa937b38
3
+ metadata.gz: d8f66324c452a30143941262a58e3f45ed167b62
4
+ data.tar.gz: a10f57987da1fc94474bbd233c0be1e7f488991d
5
5
  SHA512:
6
- metadata.gz: 732b84d4d47e6ed0137746a7947834bf75884195db19700b0962337197e4e4e49f42571568f5778371fc73e34812e8789296e4fff914e05e09dd5936f05c004c
7
- data.tar.gz: f008e5892a26270fb68ae2773e90d1036d33bcfe8f5ad50a558403742cb8592833f7727ed71af701c3201263745d3d7d492ac4d599646bb481aa968e9033d97a
6
+ metadata.gz: 48affbf85e24d2ca9b6fb750983abbf1ecab8c5016392cd19ee2dcf95c09d77a208b72fbd7dca1e04f5ee031229fa69cc60a5e247cb656e3d46cea383cf734a8
7
+ data.tar.gz: a596402fdb07093f51aa8c9a612a98046f262b52e5601c24800cb8bdef827bef6e5b2208cf6155a78258db5e44651f6be842f11fb8a2bb29b3f4dfb994ffeec9
data/README.md CHANGED
@@ -49,6 +49,9 @@ Make sure that the datatype of this columns is `hstore`:
49
49
  ```ruby
50
50
  class CreatePages < ActiveRecord::Migration
51
51
  def change
52
+ # Make sure you enable the hstore extenion
53
+ enable_extension 'hstore' unless extension_enabled?('hstore')
54
+
52
55
  create_table :pages do |t|
53
56
  t.column :title, :hstore
54
57
  t.column :content, :hstore
@@ -143,6 +146,21 @@ Page.create!(:title_en => 'Another English title', :title_de => 'Noch ein Deutsc
143
146
  Page.where(title: 'Another English title') # => Page
144
147
  ```
145
148
 
149
+ ### Limitations
150
+ `awesome_hstore_translate` patches ActiveRecord, which create the limitation, that a with `where` chained `first_or_create` and `first_or_create!` **doesn't work** as expected.
151
+ Here is an example, which **won't** work:
152
+
153
+ ``` ruby
154
+ Page.where(title: 'Titre français').first_or_create!
155
+ ```
156
+
157
+ A workaround is:
158
+
159
+ ``` ruby
160
+ Page.where(title: 'Titre français').first_or_create!(title: 'Titre français')
161
+ ```
162
+
163
+ The where clause is internally rewritten to `WHERE 'Titre français' = any(avals(title))`, so the `title: 'Titre français'` is not bound to the scope.
146
164
 
147
165
  ### Upgrade from [`hstore_translate`](https://github.com/Leadformance/hstore_translate)
148
166
  1. Replace the [`hstore_translate`](https://github.com/Leadformance/hstore_translate) with `awesome_hstore_translate` in your Gemfile
@@ -7,7 +7,7 @@ module AwesomeHstoreTranslate
7
7
  if attrs.is_a?(Hash) && contains_translated_attributes(attrs)
8
8
  where(attrs).limit(1).first
9
9
  else
10
- super(args)
10
+ super
11
11
  end
12
12
  end
13
13
 
@@ -4,16 +4,15 @@ module AwesomeHstoreTranslate
4
4
  protected
5
5
 
6
6
  def read_translated_attribute(attr, locale = I18n.locale)
7
- locales = []
8
- locales << locale
7
+ locales = Array(locale)
9
8
  locales += get_fallback_for_locale(locale) || [] if translation_options[:fallbacks]
10
9
 
11
10
  translations = read_raw_attribute(attr)
12
11
 
13
12
  if translations
14
- locales.uniq.each do |cur|
15
- if translations.has_key?(cur.to_s) && !translations[cur.to_s].empty?
16
- return translations[cur.to_s]
13
+ locales.map(&:to_s).uniq.each do |cur|
14
+ if translations.has_key?(cur) && !translations[cur].blank?
15
+ return translations[cur]
17
16
  end
18
17
  end
19
18
  end
@@ -50,4 +49,4 @@ module AwesomeHstoreTranslate
50
49
  end
51
50
  end
52
51
  end
53
- end
52
+ end
@@ -6,11 +6,11 @@ module AwesomeHstoreTranslate
6
6
  translated_attrs = translated_attributes(opts)
7
7
  normal_attrs = opts.reject{ |key, _| translated_attrs.include? key}
8
8
  query = spawn
9
- query.where!(normal_attrs) unless normal_attrs.empty?
9
+ query.where!(normal_attrs, *rest) unless normal_attrs.empty?
10
10
 
11
11
  translated_attrs.each do |attribute|
12
12
  if opts[attribute].is_a?(String)
13
- query.where!("'#{opts[attribute]}' = any(avals(#{attribute}))")
13
+ query.where!(":key = any(avals(#{attribute}))", key: opts[attribute])
14
14
  else
15
15
  super
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module AwesomeHstoreTranslate
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_hstore_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Bühler
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-30 00:00:00.000000000 Z
12
+ date: 2016-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord