hstorly 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +87 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/hstorly.gemspec +29 -0
- data/lib/hstorly.rb +5 -0
- data/lib/hstorly/active_record_extensions.rb +56 -0
- data/lib/hstorly/version.rb +3 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75ec9f3d16187723f5900157ab40910759cdfd52
|
4
|
+
data.tar.gz: 2366d13bf677325c9a821ae7f6b7d0d9c835eb70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44090a35df02842c32b03e56942a344f8229b7306440fec10e810e11085b64e29b098d4d428b75e931807816aaaf8841e074252998d7b27f9e87239037f9628d
|
7
|
+
data.tar.gz: fbbcb07c787606f7022952760a998c2cf2541ffd707d4b8c36ba8ffd3d4e20bf0ff7362894beaf57c886ea2215a0ccbf6ca295fbf4e8975e1a92b3f6540490a1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Hstorly
|
2
|
+
|
3
|
+
This project is a fork of the amazing [bithavoc/multilang-hstore](https://github.com/bithavoc/multilang-hstore) with some remarkable differences.
|
4
|
+
|
5
|
+
* Focus on performance. Especially when dealing with millions of records,
|
6
|
+
every operation counts.
|
7
|
+
* Remove a lot of features, focus on the core features.
|
8
|
+
* Due to focus on core features, better thread safety.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'hstorly'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install hstorly
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
This is a walkthrough with all steps you need to setup multilang translated attributes, including model and migration.
|
29
|
+
|
30
|
+
We're assuming here you want a Post model with some multilang attributes, as outlined below:
|
31
|
+
|
32
|
+
class Post < ActiveRecord::Base
|
33
|
+
hstore_translate :title
|
34
|
+
end
|
35
|
+
|
36
|
+
The multilang translations are stored in the same model attributes (eg. title):
|
37
|
+
|
38
|
+
You may need to create migration for Post as usual, but multilang attributes should be in hstore type:
|
39
|
+
|
40
|
+
create_table(:posts) do |t|
|
41
|
+
t.hstore :title
|
42
|
+
t.timestamps
|
43
|
+
end
|
44
|
+
|
45
|
+
Thats it!
|
46
|
+
|
47
|
+
Now you are able to translate values for the attributes :title and :description per locale:
|
48
|
+
|
49
|
+
I18n.locale = :en
|
50
|
+
post.title = 'Hstorly rocks!'
|
51
|
+
I18n.locale = :de
|
52
|
+
post.title = 'Hstorly pferdefleisch!'
|
53
|
+
|
54
|
+
I18n.locale = :en
|
55
|
+
post.title #=> Hstorly rocks!
|
56
|
+
I18n.locale = :de
|
57
|
+
post.title #=> Hstorly pferdefleisch!
|
58
|
+
|
59
|
+
If this is not enough, and sometimes you want to access one of the attributes directly you can also do:
|
60
|
+
|
61
|
+
post.title_en = 'Hulk > Time punch'
|
62
|
+
post.title_en #=> Hulk > Time punch
|
63
|
+
|
64
|
+
|
65
|
+
You may use initialization if needed:
|
66
|
+
|
67
|
+
Post.new(title: {en: 'Cows rock', de: 'Kühe rocken'})
|
68
|
+
|
69
|
+
## Bugs and Feedback
|
70
|
+
|
71
|
+
Use [http://github.com/hendricius/hstorly/issues](http://github.com/hendricius/hstorly/issues)
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
76
|
+
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hendricius/hstorly.
|
83
|
+
|
84
|
+
## License(MIT)
|
85
|
+
|
86
|
+
* Copyright (c) 2015 Hendrik Kleinwaechter and Contributors
|
87
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hstorly"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/hstorly.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hstorly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hstorly"
|
8
|
+
spec.version = Hstorly::VERSION
|
9
|
+
spec.authors = ["Hendrik Kleinwaechter"]
|
10
|
+
spec.email = ["hendrik.kleinwaechter@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Fast and efficient model translations in the database for PostgreSQL and Hstore}
|
13
|
+
spec.description = %q{Fast and efficient model translations in the databse for PostgreSQL and Hstore.}
|
14
|
+
spec.homepage = "https://github.com/hendricius/hstorly"
|
15
|
+
spec.license = "ruby"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 0"
|
25
|
+
spec.add_development_dependency "pry", "~> 0"
|
26
|
+
|
27
|
+
spec.add_dependency 'pg', '~> 0.0'
|
28
|
+
spec.add_dependency 'activerecord', '~> 4.0'
|
29
|
+
end
|
data/lib/hstorly.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Hstorly
|
2
|
+
module ActiveRecordExtensions
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def hstore_translate(*args)
|
7
|
+
|
8
|
+
|
9
|
+
args.each do |attribute|
|
10
|
+
|
11
|
+
define_method attribute do
|
12
|
+
(self[attribute] || {})[I18n.locale.to_s] || ""
|
13
|
+
end
|
14
|
+
|
15
|
+
define_method "#{attribute}=" do |value|
|
16
|
+
if self[attribute].present?
|
17
|
+
write_attribute attribute, send(attribute).merge({I18n.locale => value })
|
18
|
+
else
|
19
|
+
write_attribute attribute, {I18n.locale => value }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method "#{attribute}_before_type_cast" do
|
24
|
+
self[attribute] || {}
|
25
|
+
end
|
26
|
+
|
27
|
+
module_eval do
|
28
|
+
serialize "#{attribute}", ActiveRecord::Coders::Hstore
|
29
|
+
end if defined?(ActiveRecord::Coders::Hstore)
|
30
|
+
|
31
|
+
|
32
|
+
I18n.available_locales.map(&:to_s).each do |locale|
|
33
|
+
|
34
|
+
define_method "#{attribute}_#{locale}" do
|
35
|
+
(self[attribute] || {})[locale] || ""
|
36
|
+
end
|
37
|
+
|
38
|
+
define_method "#{attribute}_#{locale}=" do |value|
|
39
|
+
if self[attribute].present?
|
40
|
+
write_attribute attribute, self[attribute].merge({locale => value })
|
41
|
+
else
|
42
|
+
write_attribute attribute, {locale => value }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
ActiveRecord::Base.extend Hstorly::ActiveRecordExtensions::ClassMethods
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hstorly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hendrik Kleinwaechter
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
97
|
+
description: Fast and efficient model translations in the databse for PostgreSQL and
|
98
|
+
Hstore.
|
99
|
+
email:
|
100
|
+
- hendrik.kleinwaechter@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- hstorly.gemspec
|
113
|
+
- lib/hstorly.rb
|
114
|
+
- lib/hstorly/active_record_extensions.rb
|
115
|
+
- lib/hstorly/version.rb
|
116
|
+
homepage: https://github.com/hendricius/hstorly
|
117
|
+
licenses:
|
118
|
+
- ruby
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.5
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Fast and efficient model translations in the database for PostgreSQL and
|
140
|
+
Hstore
|
141
|
+
test_files: []
|
142
|
+
has_rdoc:
|