trasto 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.rspec +2 -0
- data/.rubocop.yml +14 -3
- data/.travis.yml +9 -6
- data/Appraisals +13 -9
- data/Gemfile +2 -0
- data/LICENSE.txt +2 -2
- data/README.md +38 -25
- data/Rakefile +2 -0
- data/gemfiles/5.2.gemfile +10 -0
- data/gemfiles/6.0.gemfile +10 -0
- data/gemfiles/6.1.gemfile +10 -0
- data/lib/trasto.rb +2 -0
- data/lib/trasto/class_methods.rb +4 -2
- data/lib/trasto/instance_methods.rb +2 -0
- data/lib/trasto/translates.rb +3 -1
- data/lib/trasto/version.rb +3 -1
- data/spec/app/post.rb +2 -0
- data/spec/spec_helper.rb +7 -8
- data/spec/trasto_spec.rb +12 -8
- data/trasto.gemspec +11 -9
- metadata +28 -28
- data/gemfiles/3.2.gemfile +0 -8
- data/gemfiles/4.0.gemfile +0 -7
- data/gemfiles/4.1.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c3826d44d5251ebed8b80f0d95a592b2c1bfaf4b4ce1ca52d8b1874aeb50ddb5
|
4
|
+
data.tar.gz: 5ce4a554d26aa0b5992ec7cd2dd3f494cf02bdb8779a39374344ad8c29b43239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a03e2672397e1656c23b160a901fd6aec24efa27f5ff22a9010ee4ebc3d1bbfc529b7a8f96acd818a901ef947685465166416ac9efe3d1a696e1cc772bd8400
|
7
|
+
data.tar.gz: 6135c9760edb68ccbcc0b5f79143db32bf5e30b8b5f9863f9d56265f0d3abe88137f1b06b29a8bbf7c34b46d9c94897e779b9b56853c80f841b025e0ae8c7224
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rubocop.yml
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
3
|
|
4
|
-
|
4
|
+
Metrics/BlockLength:
|
5
|
+
Exclude:
|
6
|
+
- 'Rakefile'
|
7
|
+
- '**/*.rake'
|
8
|
+
- 'test/**/*.rb'
|
9
|
+
- 'spec/**/*.rb'
|
10
|
+
|
11
|
+
Layout/LineLength:
|
12
|
+
Exclude:
|
13
|
+
- '*.gemspec'
|
14
|
+
|
15
|
+
Style/Documentation:
|
5
16
|
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
|
4
|
+
services:
|
5
|
+
- postgresql
|
6
|
+
|
4
7
|
rvm:
|
5
|
-
- "
|
6
|
-
- "2.
|
7
|
-
- "2.
|
8
|
+
- "2.5.8"
|
9
|
+
- "2.6.6"
|
10
|
+
- "2.7.2"
|
8
11
|
|
9
12
|
gemfile:
|
10
|
-
- gemfiles/
|
11
|
-
- gemfiles/
|
12
|
-
- gemfiles/
|
13
|
+
- gemfiles/6.1.gemfile
|
14
|
+
- gemfiles/6.0.gemfile
|
15
|
+
- gemfiles/5.2.gemfile
|
13
16
|
|
14
17
|
before_script:
|
15
18
|
- psql -c 'create database "trasto-test";' -U postgres
|
data/Appraisals
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# vim: set ft=ruby :
|
5
4
|
|
6
|
-
appraise
|
7
|
-
gem
|
5
|
+
appraise '6.1' do
|
6
|
+
gem 'activerecord', '~> 6.1.0'
|
7
|
+
gem 'silent_stream'
|
8
8
|
end
|
9
9
|
|
10
|
-
appraise
|
11
|
-
gem
|
10
|
+
appraise '6.0' do
|
11
|
+
gem 'activerecord', '~> 6.0.0'
|
12
|
+
gem 'silent_stream'
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
+
appraise '5.2' do
|
16
|
+
gem 'activerecord', '~> 5.2.0'
|
17
|
+
gem 'silent_stream'
|
18
|
+
end
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Morton Jonuschat
|
1
|
+
Copyright (c) 2012-2015 Morton Jonuschat
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/yabawock/trasto.png)](http://travis-ci.org/yabawock/trasto)
|
4
4
|
|
5
|
-
Translatable columns for Rails
|
5
|
+
Translatable columns for Rails 4, directly stored in a postgres hstore in the model table.
|
6
6
|
|
7
7
|
Inspired by Barsoom's [traco](https://github.com/barsoom/traco/).
|
8
8
|
|
@@ -14,24 +14,28 @@ Say you want `Post#title` and `Post#body` to support both English and Swedish va
|
|
14
14
|
|
15
15
|
Write a migration to get hstore database columns with i18n suffixes, e.g. `title_i18n` and `body_i18n`, like:
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
```ruby
|
18
|
+
class CreatePosts < ActiveRecord::Migration
|
19
|
+
def change
|
20
|
+
create_table :posts do |t|
|
21
|
+
t.hstore :title_i18n
|
22
|
+
t.hstore :body_i18n
|
22
23
|
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
24
|
+
t.timestamps
|
26
25
|
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
```
|
27
29
|
|
28
30
|
Don't create `title` or `body` columns without the `_i18n` suffix, Trasto will define a method with that name.
|
29
31
|
|
30
32
|
Declare these columns in the model:
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
```ruby
|
35
|
+
class Post < ActiveRecord::Base
|
36
|
+
translates :title, :body
|
37
|
+
end
|
38
|
+
```
|
35
39
|
|
36
40
|
You can still use your accessors for `title_i18n` and `title_i18=` in forms, validations and other code, but you also get:
|
37
41
|
|
@@ -43,31 +47,40 @@ You can still use your accessors for `title_i18n` and `title_i18=` in forms, val
|
|
43
47
|
|
44
48
|
## Installation
|
45
49
|
|
46
|
-
Add this to your `Gemfile
|
47
|
-
|
48
|
-
gem 'trasto'
|
49
|
-
|
50
|
-
If you're using Rails 3, add the following gem:
|
50
|
+
Add this to your `Gemfile`:
|
51
51
|
|
52
|
-
|
52
|
+
```ruby
|
53
|
+
gem 'trasto'
|
54
|
+
```
|
53
55
|
|
54
|
-
|
56
|
+
You might need to enable the hstore extension for your database. Create a migration containing the necessary instruction:
|
55
57
|
|
56
|
-
|
58
|
+
```ruby
|
59
|
+
class EnableHstore < ActiveRecord::Migration
|
60
|
+
def change
|
61
|
+
enable_extension 'hstore'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
57
65
|
|
58
|
-
|
66
|
+
## Running the tests
|
59
67
|
|
68
|
+
```
|
69
|
+
bundle exec appraisal install
|
70
|
+
bundle exec appraisal rake
|
71
|
+
```
|
60
72
|
|
61
|
-
|
73
|
+
To run only one appraisal/gemfile:
|
62
74
|
|
63
|
-
|
64
|
-
|
75
|
+
```
|
76
|
+
bundle exec appraisal 4.2 rake
|
77
|
+
```
|
65
78
|
|
66
79
|
## Credits and license
|
67
80
|
|
68
81
|
By [Morton Jonuschat](https://github.com/yabawock) under the MIT license:
|
69
82
|
|
70
|
-
> Copyright (c) 2012-
|
83
|
+
> Copyright (c) 2012-2015 Morton Jonuschat
|
71
84
|
>
|
72
85
|
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
73
86
|
> of this software and associated documentation files (the "Software"), to deal
|
data/Rakefile
CHANGED
data/lib/trasto.rb
CHANGED
data/lib/trasto/class_methods.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Trasto
|
2
4
|
module ClassMethods
|
3
|
-
private
|
4
|
-
|
5
5
|
def translates?(column)
|
6
6
|
translatable_columns.include?(column.to_sym)
|
7
7
|
end
|
8
8
|
|
9
|
+
private
|
10
|
+
|
9
11
|
def locale_name(locale)
|
10
12
|
I18n.t(locale, scope: :"i18n.languages", default: locale.to_s.upcase)
|
11
13
|
end
|
data/lib/trasto/translates.rb
CHANGED
data/lib/trasto/version.rb
CHANGED
data/spec/app/post.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.configure do |config|
|
2
4
|
# Clear class state before each spec.
|
3
5
|
config.before(:each) do
|
@@ -12,20 +14,17 @@ end
|
|
12
14
|
# https://github.com/iain/translatable_columns/
|
13
15
|
|
14
16
|
require 'active_record'
|
17
|
+
require 'silent_stream'
|
18
|
+
require 'trasto'
|
15
19
|
|
16
|
-
|
17
|
-
require 'activerecord-postgres-hstore'
|
18
|
-
require 'activerecord-postgres-hstore/activerecord'
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'app/post.rb'
|
20
|
+
require 'app/post'
|
22
21
|
require 'pry'
|
23
22
|
|
24
23
|
ActiveRecord::Base.establish_connection adapter: 'postgresql', database: 'trasto-test'
|
25
24
|
|
26
|
-
I18n.enforce_available_locales
|
25
|
+
I18n.enforce_available_locales = false
|
27
26
|
|
28
|
-
silence_stream(
|
27
|
+
Class.new.include(SilentStream).silence_stream($stdout) do
|
29
28
|
ActiveRecord::Schema.define(version: 0) do
|
30
29
|
execute 'CREATE EXTENSION IF NOT EXISTS hstore'
|
31
30
|
|
data/spec/trasto_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'trasto'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
describe ActiveRecord::Base, '.translates' do
|
5
|
-
|
6
4
|
it 'should be available' do
|
7
5
|
expect(Post).to respond_to :translates
|
8
6
|
end
|
@@ -27,11 +25,21 @@ describe ActiveRecord::Base, '.translates' do
|
|
27
25
|
expect(Post.new).to respond_to :title
|
28
26
|
expect(Post.new).not_to respond_to :body
|
29
27
|
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ActiveRecord::Base, '.translates?' do
|
31
|
+
it 'inherits columns from the superclass' do
|
32
|
+
Post.translates :title
|
33
|
+
SubPost.translates :body
|
30
34
|
|
35
|
+
expect(SubPost.translates?(:title)).to be true
|
36
|
+
expect(SubPost.translates?(:body)).to be true
|
37
|
+
expect(Post.translates?(:title)).to be true
|
38
|
+
expect(Post.translates?(:body)).to be false
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
42
|
describe Post, '.translatable_columns' do
|
34
|
-
|
35
43
|
before do
|
36
44
|
Post.translates :title
|
37
45
|
end
|
@@ -39,11 +47,9 @@ describe Post, '.translatable_columns' do
|
|
39
47
|
it 'should list the translatable columns' do
|
40
48
|
expect(Post.translatable_columns).to eq([:title])
|
41
49
|
end
|
42
|
-
|
43
50
|
end
|
44
51
|
|
45
52
|
describe Post, '#title' do
|
46
|
-
|
47
53
|
let(:post) { Post.new(title_i18n: { de: 'Hallo', en: 'Hello', sv: 'Hej' }) }
|
48
54
|
|
49
55
|
before do
|
@@ -88,7 +94,6 @@ describe Post, '#title' do
|
|
88
94
|
end
|
89
95
|
|
90
96
|
describe Post, '#title=' do
|
91
|
-
|
92
97
|
before do
|
93
98
|
Post.translates :title
|
94
99
|
I18n.locale = :de
|
@@ -101,5 +106,4 @@ describe Post, '#title=' do
|
|
101
106
|
expect(post.title).to eq('Hallo')
|
102
107
|
expect(post.title_i18n['de']).to eq('Hallo')
|
103
108
|
end
|
104
|
-
|
105
109
|
end
|
data/trasto.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'trasto/version'
|
5
6
|
|
@@ -8,19 +9,20 @@ Gem::Specification.new do |gem|
|
|
8
9
|
gem.version = Trasto::VERSION
|
9
10
|
gem.authors = ['Morton Jonuschat']
|
10
11
|
gem.email = ['yabawock@gmail.com']
|
11
|
-
gem.description = 'Translatable columns for Rails
|
12
|
+
gem.description = 'Translatable columns for Rails 4, directly stored in a Postgres hstore in the model table.'
|
12
13
|
gem.summary = 'Use PostgreSQL hstore to keep column translations in the model table without adding lots of tables/columns.'
|
13
14
|
gem.homepage = 'https://github.com/yabawock/trasto'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
|
-
gem.executables = gem.files.grep(
|
17
|
-
gem.test_files = gem.files.grep(
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ['lib']
|
19
20
|
|
20
|
-
gem.
|
21
|
+
gem.required_ruby_version = '>= 2.5.0'
|
22
|
+
gem.add_dependency 'pg'
|
21
23
|
|
22
|
-
gem.add_development_dependency 'rake'
|
23
|
-
gem.add_development_dependency 'rspec', '~> 3.0'
|
24
|
-
gem.add_development_dependency 'pry'
|
25
24
|
gem.add_development_dependency 'appraisal'
|
25
|
+
gem.add_development_dependency 'pry'
|
26
|
+
gem.add_development_dependency 'rake'
|
27
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
26
28
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trasto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morton Jonuschat
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: appraisal
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,21 +39,21 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '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: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,20 +67,20 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
description: Translatable columns for Rails
|
82
|
+
version: '3.0'
|
83
|
+
description: Translatable columns for Rails 4, directly stored in a Postgres hstore
|
84
84
|
in the model table.
|
85
85
|
email:
|
86
86
|
- yabawock@gmail.com
|
@@ -89,6 +89,7 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- ".gitignore"
|
92
|
+
- ".rspec"
|
92
93
|
- ".rubocop.yml"
|
93
94
|
- ".travis.yml"
|
94
95
|
- Appraisals
|
@@ -96,9 +97,9 @@ files:
|
|
96
97
|
- LICENSE.txt
|
97
98
|
- README.md
|
98
99
|
- Rakefile
|
99
|
-
- gemfiles/
|
100
|
-
- gemfiles/
|
101
|
-
- gemfiles/
|
100
|
+
- gemfiles/5.2.gemfile
|
101
|
+
- gemfiles/6.0.gemfile
|
102
|
+
- gemfiles/6.1.gemfile
|
102
103
|
- lib/trasto.rb
|
103
104
|
- lib/trasto/class_methods.rb
|
104
105
|
- lib/trasto/instance_methods.rb
|
@@ -112,7 +113,7 @@ files:
|
|
112
113
|
homepage: https://github.com/yabawock/trasto
|
113
114
|
licenses: []
|
114
115
|
metadata: {}
|
115
|
-
post_install_message:
|
116
|
+
post_install_message:
|
116
117
|
rdoc_options: []
|
117
118
|
require_paths:
|
118
119
|
- lib
|
@@ -120,16 +121,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
121
|
requirements:
|
121
122
|
- - ">="
|
122
123
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
124
|
+
version: 2.5.0
|
124
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
126
|
requirements:
|
126
127
|
- - ">="
|
127
128
|
- !ruby/object:Gem::Version
|
128
129
|
version: '0'
|
129
130
|
requirements: []
|
130
|
-
|
131
|
-
|
132
|
-
signing_key:
|
131
|
+
rubygems_version: 3.1.4
|
132
|
+
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Use PostgreSQL hstore to keep column translations in the model table without
|
135
135
|
adding lots of tables/columns.
|
data/gemfiles/3.2.gemfile
DELETED
data/gemfiles/4.0.gemfile
DELETED