hstorly 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/hstorly.gemspec +2 -2
- data/lib/hstorly/active_record_extensions.rb +11 -0
- data/lib/hstorly/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dce5fe6fd61b0942999ad407e5d4637e80207fcd
|
4
|
+
data.tar.gz: 5e0a106d63ff03539ee92b801ce4cd9bec1f68c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 427870e73b2bda99ec23f50acc99306e6257fda64f641a047b596a771312d67c04205e56ac4851077baceb5bf3a7fc2f61488d0df8c8b796cb3cf363772ef0b4
|
7
|
+
data.tar.gz: f22eee703010e18c6fc386a7892ae8f1b2e019f384c7477eab275cf27735ec657d2c6d63a94a71f72c015a7351e05e48680feb10419029c2e12409f79f193a0e
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Hstorly
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/hendricius/multilang-hstore.svg)](https://travis-ci.org/hendricius/multilang-hstore)
|
4
|
+
|
3
5
|
This project is a fork of the amazing [bithavoc/multilang-hstore](https://github.com/bithavoc/multilang-hstore) with some remarkable differences.
|
4
6
|
|
5
7
|
* Focus on performance. Especially when dealing with millions of records,
|
@@ -36,7 +38,7 @@ We're assuming here you want a Post model with some multilang attributes, as out
|
|
36
38
|
The multilang translations are stored in the same model attributes (eg. title):
|
37
39
|
|
38
40
|
You may need to create migration for Post as usual, but multilang attributes should be in hstore type:
|
39
|
-
|
41
|
+
|
40
42
|
create_table(:posts) do |t|
|
41
43
|
t.hstore :title
|
42
44
|
t.timestamps
|
data/hstorly.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "minitest", "~> 0"
|
25
|
-
spec.add_development_dependency "pry", "~> 0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
spec.add_development_dependency "pry", "~> 0.1"
|
26
26
|
|
27
27
|
spec.add_dependency 'pg', '~> 0.0'
|
28
28
|
spec.add_dependency 'activerecord', '~> 4.0'
|
@@ -8,18 +8,27 @@ module Hstorly
|
|
8
8
|
|
9
9
|
args.each do |attribute|
|
10
10
|
|
11
|
+
# read the attribute from the hstore attribute and return it.
|
12
|
+
#
|
13
|
+
# returns the attribute or an empty string if the attribute is nil
|
11
14
|
define_method attribute do
|
12
15
|
(self[attribute] || {})[I18n.locale.to_s] || ""
|
13
16
|
end
|
14
17
|
|
18
|
+
# set the attribute on the model on the hstore hash
|
19
|
+
#
|
20
|
+
# returns the new value
|
15
21
|
define_method "#{attribute}=" do |value|
|
16
22
|
if self[attribute].present?
|
17
23
|
write_attribute attribute, send(attribute).merge({I18n.locale => value })
|
24
|
+
value
|
18
25
|
else
|
19
26
|
write_attribute attribute, {I18n.locale => value }
|
27
|
+
value
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
31
|
+
# returns the raw hstore directly
|
23
32
|
define_method "#{attribute}_before_type_cast" do
|
24
33
|
self[attribute] || {}
|
25
34
|
end
|
@@ -29,6 +38,8 @@ module Hstorly
|
|
29
38
|
end if defined?(ActiveRecord::Coders::Hstore)
|
30
39
|
|
31
40
|
|
41
|
+
# for each locale add a getter and setter method in the type of
|
42
|
+
# title_de or title_en
|
32
43
|
I18n.available_locales.map(&:to_s).each do |locale|
|
33
44
|
|
34
45
|
define_method "#{attribute}_#{locale}" do
|
data/lib/hstorly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hstorly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hendrik Kleinwaechter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '5.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '5.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '0.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pg
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|