awesome_hstore_translate 0.2.0 → 0.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b7a102f4de133d326d96a0b697f2c546409ce88
|
4
|
+
data.tar.gz: 032d0828417f873bb3b4772fb4da311baa937b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 732b84d4d47e6ed0137746a7947834bf75884195db19700b0962337197e4e4e49f42571568f5778371fc73e34812e8789296e4fff914e05e09dd5936f05c004c
|
7
|
+
data.tar.gz: f008e5892a26270fb68ae2773e90d1036d33bcfe8f5ad50a558403742cb8592833f7727ed71af701c3201263745d3d7d492ac4d599646bb481aa968e9033d97a
|
data/README.md
CHANGED
@@ -15,8 +15,7 @@ This gem uses PostgreSQLs hstore datatype and ActiveRecord models to translate m
|
|
15
15
|
- [x] `v0.1.0` Language specific accessors
|
16
16
|
- [x] `v0.2.0` Awesome Hstore Translate as drop in replace for [`hstore_translate`](https://github.com/Leadformance/hstore_translate)
|
17
17
|
- `with_[attr]_translation(str)` is not supported
|
18
|
-
- [x] `v0.2.0` Support record selection via ActiveRecord (e. g. `where`, `find_by
|
19
|
-
- maybe it's a bad idea to implement this
|
18
|
+
- [x] `v0.2.0` Support record selection via ActiveRecord (e. g. `where`, `find_by`, ..)
|
20
19
|
- [ ] `backlog` Support `friendly_id` (see `friendly_id-awesome_hstore` gem)
|
21
20
|
|
22
21
|
## Requirements
|
@@ -83,7 +82,7 @@ p.title_raw # => {'en' => 'English title', 'de' => 'Deutscher Titel'}
|
|
83
82
|
|
84
83
|
|
85
84
|
### Fallbacks
|
86
|
-
To enable fallbacks you can set `I18n.fallbacks` to `true` or enable it manually in the model:
|
85
|
+
It's possible to fall back to another language, if there is no or an empty value for the primary language. To enable fallbacks you can set `I18n.fallbacks` to `true` or enable it manually in the model:
|
87
86
|
```ruby
|
88
87
|
class Page < ActiveRecord::Base
|
89
88
|
translates :title, :content, fallbacks: true
|
@@ -1,15 +1,8 @@
|
|
1
1
|
module AwesomeHstoreTranslate
|
2
2
|
module ActiveRecord
|
3
3
|
module QueryMethods
|
4
|
-
class WhereChain < ::ActiveRecord::QueryMethods::WhereChain
|
5
|
-
end
|
6
|
-
|
7
4
|
def where(opts = :chain, *rest)
|
8
|
-
if opts
|
9
|
-
WhereChain.new(spawn)
|
10
|
-
elsif opts.blank?
|
11
|
-
return self
|
12
|
-
elsif opts.is_a?(Hash)
|
5
|
+
if opts.is_a?(Hash)
|
13
6
|
translated_attrs = translated_attributes(opts)
|
14
7
|
normal_attrs = opts.reject{ |key, _| translated_attrs.include? key}
|
15
8
|
query = spawn
|
@@ -19,12 +12,13 @@ module AwesomeHstoreTranslate
|
|
19
12
|
if opts[attribute].is_a?(String)
|
20
13
|
query.where!("'#{opts[attribute]}' = any(avals(#{attribute}))")
|
21
14
|
else
|
22
|
-
super
|
15
|
+
super
|
23
16
|
end
|
24
17
|
end
|
25
|
-
|
18
|
+
query
|
19
|
+
else
|
20
|
+
super
|
26
21
|
end
|
27
|
-
super(opts, rest)
|
28
22
|
end
|
29
23
|
|
30
24
|
private
|