traco 5.2.0 → 5.3.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 +4 -4
- data/lib/traco/attributes.rb +6 -5
- data/lib/traco/version.rb +1 -1
- data/spec/traco_spec.rb +27 -1
- metadata +10 -26
- data/.gitignore +0 -7
- data/.rspec +0 -1
- data/.travis.yml +0 -24
- data/Appraisals +0 -26
- data/CHANGELOG.md +0 -83
- data/Gemfile +0 -8
- data/README.md +0 -178
- data/Rakefile +0 -6
- data/benchmarks/overhead.rb +0 -41
- data/gemfiles/rails_4.2.gemfile +0 -12
- data/gemfiles/rails_5.0.gemfile +0 -12
- data/gemfiles/rails_5.1.gemfile +0 -12
- data/gemfiles/rails_5.2.gemfile +0 -11
- data/gemfiles/rails_6.0.gemfile +0 -11
- data/gemfiles/rails_6.1.gemfile +0 -11
- data/traco.gemspec +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d3d3ad540b0b54d9a5ce5adb2128e2edb4f3a1639cc943005bf8f0ffc59046
|
4
|
+
data.tar.gz: 28ac1c659ba7e3b6160e5d7da6bd995a2a0a12c08b0e070d461b45b85cc751ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2bd0a863da9ad824af47836f419f0b89ffd366aebf45a05772c2d109249effde7f5f18904480da34fd7d4deaf338125cfc5e8a74926c24ea6eecac8a16419dd
|
7
|
+
data.tar.gz: 6604dbef3ea352ecb532aa77b826e15664cb407bf168240d254f194b0be9340ced3791eda23d45199d14860c8a0f3364bb78c3d0ef257a0a9d565f3d8bb90a29
|
data/lib/traco/attributes.rb
CHANGED
@@ -21,10 +21,11 @@ module Traco
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def define_reader(attribute)
|
24
|
+
default_fallback = @options.fetch(:fallback, LocaleFallbacks::DEFAULT_FALLBACK)
|
25
|
+
|
24
26
|
class_eval <<-EOM, __FILE__, __LINE__ + 1
|
25
|
-
def #{attribute}(
|
26
|
-
|
27
|
-
fallback = options.fetch(:fallback, default_fallback)
|
27
|
+
def #{attribute}(locale: nil, fallback: #{default_fallback.inspect})
|
28
|
+
return send(Traco.column(:#{attribute}, locale)) if locale
|
28
29
|
|
29
30
|
columns_to_try = self.class._locale_columns_for_attribute(:#{attribute}, fallback: fallback)
|
30
31
|
columns_to_try.each do |column|
|
@@ -48,8 +49,8 @@ module Traco
|
|
48
49
|
|
49
50
|
def define_query(attribute)
|
50
51
|
class_eval <<-EOM, __FILE__, __LINE__ + 1
|
51
|
-
def #{attribute}?
|
52
|
-
|
52
|
+
def #{attribute}?(locale: nil)
|
53
|
+
send(:#{attribute}, locale: locale).present?
|
53
54
|
end
|
54
55
|
EOM
|
55
56
|
end
|
data/lib/traco/version.rb
CHANGED
data/spec/traco_spec.rb
CHANGED
@@ -230,6 +230,19 @@ RSpec.describe Post, "#title" do
|
|
230
230
|
expect(post.title).to eq "Hej"
|
231
231
|
end
|
232
232
|
|
233
|
+
context "when given a 'locale' argument" do
|
234
|
+
it "gives the title in that locale, without fallback" do
|
235
|
+
post = Post.new(title_sv: "Hej", title_en: "Halloa")
|
236
|
+
I18n.default_locale = :en
|
237
|
+
I18n.locale = :en
|
238
|
+
|
239
|
+
expect(post.title(locale: :sv)).to eq "Hej"
|
240
|
+
|
241
|
+
post.title_sv = nil
|
242
|
+
expect(post.title(locale: :sv)).to eq nil
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
233
246
|
context "when the translation was defined with fallback: false" do
|
234
247
|
let(:post) {
|
235
248
|
Post.new(title_sv: "Hej", title_en: "Halloa")
|
@@ -310,7 +323,7 @@ RSpec.describe Post, "#title?" do
|
|
310
323
|
I18n.default_locale = :en
|
311
324
|
end
|
312
325
|
|
313
|
-
it "is true if the title is present" do
|
326
|
+
it "is true if the title is present, with fallback" do
|
314
327
|
post = Post.new(title_sv: "", title_en: " ", title_pt_br: nil)
|
315
328
|
expect(post.title?).to be false
|
316
329
|
|
@@ -318,6 +331,19 @@ RSpec.describe Post, "#title?" do
|
|
318
331
|
|
319
332
|
expect(post.title?).to be true
|
320
333
|
end
|
334
|
+
|
335
|
+
context "when given a 'locale' argument" do
|
336
|
+
it "is true if the title if present in that locale, with no fallback" do
|
337
|
+
post = Post.new(title_sv: "Hej", title_en: "Halloa")
|
338
|
+
I18n.default_locale = :en
|
339
|
+
I18n.locale = :en
|
340
|
+
|
341
|
+
expect(post.title?(locale: :sv)).to be true
|
342
|
+
|
343
|
+
post.title_sv = nil
|
344
|
+
expect(post.title?(locale: :sv)).to be false
|
345
|
+
end
|
346
|
+
end
|
321
347
|
end
|
322
348
|
|
323
349
|
RSpec.describe Post, ".human_attribute_name" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -80,29 +80,14 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- henrik@barsoom.se
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- ".gitignore"
|
91
|
-
- ".rspec"
|
92
|
-
- ".travis.yml"
|
93
|
-
- Appraisals
|
94
|
-
- CHANGELOG.md
|
95
|
-
- Gemfile
|
96
90
|
- LICENSE.txt
|
97
|
-
- README.md
|
98
|
-
- Rakefile
|
99
|
-
- benchmarks/overhead.rb
|
100
|
-
- gemfiles/rails_4.2.gemfile
|
101
|
-
- gemfiles/rails_5.0.gemfile
|
102
|
-
- gemfiles/rails_5.1.gemfile
|
103
|
-
- gemfiles/rails_5.2.gemfile
|
104
|
-
- gemfiles/rails_6.0.gemfile
|
105
|
-
- gemfiles/rails_6.1.gemfile
|
106
91
|
- lib/traco.rb
|
107
92
|
- lib/traco/attributes.rb
|
108
93
|
- lib/traco/class_methods.rb
|
@@ -115,12 +100,11 @@ files:
|
|
115
100
|
- spec/spec_helper.rb
|
116
101
|
- spec/spec_helper_models.rb
|
117
102
|
- spec/traco_spec.rb
|
118
|
-
- traco.gemspec
|
119
103
|
homepage: ''
|
120
104
|
licenses:
|
121
105
|
- MIT
|
122
106
|
metadata: {}
|
123
|
-
post_install_message:
|
107
|
+
post_install_message:
|
124
108
|
rdoc_options: []
|
125
109
|
require_paths:
|
126
110
|
- lib
|
@@ -136,13 +120,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
120
|
version: '0'
|
137
121
|
requirements: []
|
138
122
|
rubygems_version: 3.1.4
|
139
|
-
signing_key:
|
123
|
+
signing_key:
|
140
124
|
specification_version: 4
|
141
125
|
summary: Translatable columns for Rails 4.2 or better, stored in the model table itself.
|
142
126
|
test_files:
|
143
|
-
- spec/app/post.rb
|
144
|
-
- spec/app/sv.yml
|
145
|
-
- spec/locale_fallbacks_spec.rb
|
146
127
|
- spec/spec_helper.rb
|
147
|
-
- spec/
|
128
|
+
- spec/app/sv.yml
|
129
|
+
- spec/app/post.rb
|
148
130
|
- spec/traco_spec.rb
|
131
|
+
- spec/spec_helper_models.rb
|
132
|
+
- spec/locale_fallbacks_spec.rb
|
data/.gitignore
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
-r spec_helper
|
data/.travis.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
rvm:
|
4
|
-
- 2.6.3
|
5
|
-
- 2.5.5
|
6
|
-
- 2.4.6
|
7
|
-
- 2.3.8
|
8
|
-
gemfile:
|
9
|
-
- gemfiles/rails_4.2.gemfile
|
10
|
-
- gemfiles/rails_5.0.gemfile
|
11
|
-
- gemfiles/rails_5.1.gemfile
|
12
|
-
- gemfiles/rails_5.2.gemfile
|
13
|
-
- gemfiles/rails_6.0.gemfile
|
14
|
-
- gemfiles/rails_6.1.gemfile
|
15
|
-
matrix:
|
16
|
-
exclude:
|
17
|
-
- rvm: 2.3.8
|
18
|
-
gemfile: gemfiles/rails_6.0.gemfile
|
19
|
-
- rvm: 2.3.8
|
20
|
-
gemfile: gemfiles/rails_6.1.gemfile
|
21
|
-
- rvm: 2.4.6
|
22
|
-
gemfile: gemfiles/rails_6.0.gemfile
|
23
|
-
- rvm: 2.4.6
|
24
|
-
gemfile: gemfiles/rails_6.1.gemfile
|
data/Appraisals
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
appraise "rails-4.2" do
|
2
|
-
gem "activerecord", "~> 4.2.0"
|
3
|
-
gem "sqlite3", "~> 1.3.13"
|
4
|
-
end
|
5
|
-
|
6
|
-
appraise "rails-5.0" do
|
7
|
-
gem "activerecord", "~> 5.0.0"
|
8
|
-
gem "sqlite3", "~> 1.3.13"
|
9
|
-
end
|
10
|
-
|
11
|
-
appraise "rails-5.1" do
|
12
|
-
gem "activerecord", "~> 5.1.0"
|
13
|
-
gem "sqlite3", "~> 1.3.13"
|
14
|
-
end
|
15
|
-
|
16
|
-
appraise "rails-5.2" do
|
17
|
-
gem "activerecord", "~> 5.2.0"
|
18
|
-
end
|
19
|
-
|
20
|
-
appraise "rails-6.0" do
|
21
|
-
gem "activerecord", "~> 6.0.3.1"
|
22
|
-
end
|
23
|
-
|
24
|
-
appraise "rails-6.1" do
|
25
|
-
gem "activerecord", "~> 6.1.0"
|
26
|
-
end
|
data/CHANGELOG.md
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
## 5.2.0
|
4
|
-
|
5
|
-
* Feature: `locale_columns` without a passed column name returns all locale columns. Thanks to [manuelmeurer](https://github.com/manuelmeurer)!
|
6
|
-
|
7
|
-
## 5.1.0
|
8
|
-
|
9
|
-
* Feature: Add `fallback: :i18n` to use the fallbacks from `I18n.fallbacks`. Thanks to [sunny](https://github.com/sunny)!
|
10
|
-
|
11
|
-
## 5.0.0
|
12
|
-
|
13
|
-
* Change `locale_columns` and `locales_for_attribute` to sort current locale first, then default locale (previously, it was default locale first). This makes more sense for our own apps, and hopefully other apps as well.
|
14
|
-
|
15
|
-
## 4.0.0
|
16
|
-
|
17
|
-
* Drop support for end-of-lifed Ruby 2.1 and 2.2.
|
18
|
-
|
19
|
-
## 3.3.0
|
20
|
-
|
21
|
-
* Traco now automatically adds query methods, e.g. `Item#title?` when `title` is translated.
|
22
|
-
|
23
|
-
## 3.2.2
|
24
|
-
|
25
|
-
* Internal cleanup.
|
26
|
-
|
27
|
-
## 3.2.1
|
28
|
-
|
29
|
-
* Bugfix: with `fallback: [:sv]`, always look at current locale before any fallbacks.
|
30
|
-
|
31
|
-
## 3.2.0
|
32
|
-
|
33
|
-
* Introduce e.g. `fallback: [:sv]` to explicitly specify fallbacks.
|
34
|
-
|
35
|
-
## 3.1.6
|
36
|
-
|
37
|
-
Make [license (MIT)](LICENSE.txt) easier to autodetect.
|
38
|
-
|
39
|
-
## 3.1.5
|
40
|
-
|
41
|
-
* Bugfix: don't raise error loading models before the DB is created. Thanks to PikachuEXE and Andrii Malyshko.
|
42
|
-
|
43
|
-
## 3.1.4
|
44
|
-
|
45
|
-
* Bugfix: restore sorting of `locale_columns` and `locales_for_attribute` to put default locale first, not current locale. Thanks to PikachuEXE.
|
46
|
-
|
47
|
-
## 3.1.3
|
48
|
-
|
49
|
-
* ~20 time speedup thanks to optimizations by Andrii Malyshko.
|
50
|
-
|
51
|
-
Reading a Traco translated attribute used to be ~250x slower than an untranslated attribute; now it's down to ~10x slower.
|
52
|
-
|
53
|
-
## 3.1.2
|
54
|
-
|
55
|
-
* Bugfix: `.current_locale_column` handles dashed locales like "pt-BR" correctly. Thanks to PikachuEXE.
|
56
|
-
|
57
|
-
## 3.1.1
|
58
|
-
|
59
|
-
* Bugfix around fallbacks and memoization. Thanks to PikachuEXE.
|
60
|
-
|
61
|
-
## 3.1.0
|
62
|
-
|
63
|
-
* Introduce `.current_locale_column`, e.g. `Post.current_locale_column(:title) # => :title_sv`.
|
64
|
-
|
65
|
-
## 3.0.0
|
66
|
-
|
67
|
-
* Backwards incompatible: `fallback: true` is now `fallback: :default`. Since this was the implicit default value, you shouldn't have a problem unless you explicitly declared this value.
|
68
|
-
|
69
|
-
## 2.2.0
|
70
|
-
|
71
|
-
* `fallback: :any` to fall back to any other locale if the text is blank in the current and default locales.
|
72
|
-
|
73
|
-
## 2.1.0
|
74
|
-
|
75
|
-
* Attribute readers can override the attribute's `fallback` setting, e.g. `item.title(fallback: false)`.
|
76
|
-
|
77
|
-
## 2.0.0
|
78
|
-
|
79
|
-
* Backwards incompatible: for dashed locales like "pt-BR", the column names are now expected to end in e.g. `_pt_br`, not `_pt-BR`.
|
80
|
-
|
81
|
-
## 1.3.0
|
82
|
-
|
83
|
-
Whatever we had before introducing this changelog.
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
# Traco
|
2
|
-
|
3
|
-
[](http://travis-ci.org/barsoom/traco)
|
4
|
-
|
5
|
-
Translatable attributes for Ruby on Rails 4.2+, stored in the model table itself.
|
6
|
-
|
7
|
-
Inspired by Iain Hecker's [translatable_columns](https://github.com/iain/translatable_columns/).
|
8
|
-
|
9
|
-
To store translations outside the model, see Sven Fuchs' [Globalize](https://github.com/globalize/globalize).
|
10
|
-
|
11
|
-
|
12
|
-
## Usage
|
13
|
-
|
14
|
-
Say you want `Post#title` and `Post#body` to support both English and Swedish values.
|
15
|
-
|
16
|
-
Write a migration to get database columns with locale suffixes, e.g. `title_sv` and `title_en`, like:
|
17
|
-
|
18
|
-
```ruby
|
19
|
-
class CreatePosts < ActiveRecord::Migration
|
20
|
-
def change
|
21
|
-
create_table :posts do |t|
|
22
|
-
t.string :title_sv, :title_en
|
23
|
-
t.text :body_sv, :body_en
|
24
|
-
|
25
|
-
t.timestamps
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
```
|
30
|
-
|
31
|
-
Don't create a database column named `title` without a suffix, since Traco will define a method with that name.
|
32
|
-
|
33
|
-
If you use a locale format like `pt-BR`, the column name would be `title_pt_br`.
|
34
|
-
|
35
|
-
Declare the attributes in the model:
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
class Post < ActiveRecord::Base
|
39
|
-
translates :title, :body
|
40
|
-
end
|
41
|
-
```
|
42
|
-
|
43
|
-
You can still use your accessors like `title_sv` and `title_sv=` in forms, validations and other code, but you also get:
|
44
|
-
|
45
|
-
`#title`: Shows the title in the current locale. If blank, falls back to default locale. Otherwise nil.
|
46
|
-
|
47
|
-
`#title=`: Assigns the title to the column for the current locale, if present. Raises if the column doesn't exist.
|
48
|
-
|
49
|
-
`#title?`: Is the title present? Respects the Traco [fallback](#fallbacks) setting.
|
50
|
-
|
51
|
-
`.human_attribute_name(:title_sv)`: Extends this standard method to return "Title (Swedish)" if you have a translation key `i18n.languages.sv = "Swedish"` and "Title (SV)" otherwise. Rails uses this method to build validation error messages and form labels.
|
52
|
-
|
53
|
-
`.translatable_attributes`: Returns an array like `[:title, :body]`.
|
54
|
-
|
55
|
-
`.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with current locale first, then default locale, and then alphabetically. Suitable for looping in forms:
|
56
|
-
|
57
|
-
```erb
|
58
|
-
<% Post.locale_columns(:title).each do |column| %>
|
59
|
-
<p>
|
60
|
-
<%= form.label column %>
|
61
|
-
<%= form.text_field column %>
|
62
|
-
</p>
|
63
|
-
<% end %>
|
64
|
-
```
|
65
|
-
|
66
|
-
Or perhaps for things like:
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
attr_accessible *locale_columns(:title)
|
70
|
-
|
71
|
-
validates *locale_columns(:title), :uniqueness => true
|
72
|
-
```
|
73
|
-
|
74
|
-
You can also pass multiple attributes if you like:
|
75
|
-
|
76
|
-
```ruby
|
77
|
-
attr_accessible *locale_columns(:title, :body)
|
78
|
-
```
|
79
|
-
|
80
|
-
The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]`.
|
81
|
-
|
82
|
-
`.current_locale_column(:title)`: Returns `:title_sv` if `:sv` is the current locale. Suitable for some SQL queries, such as sorting.
|
83
|
-
|
84
|
-
`.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with current locale first, then default locale, and then alphabetically.
|
85
|
-
|
86
|
-
And the equivalent methods for `body`, of course.
|
87
|
-
|
88
|
-
Please note that your `translates :title, :body` declaration must be called before you call `locale_columns`. Otherwise you will get an error like "NoMethodError: undefined method `locale\_columns' for #\<Class:0x00000003f69188\>".
|
89
|
-
|
90
|
-
|
91
|
-
### Fallbacks
|
92
|
-
|
93
|
-
By default, Traco will fall back to the default locale if there is no translation in the current locale.
|
94
|
-
|
95
|
-
You can specify e.g. `translates :title, fallback: false` to never fall back and instead return `nil`.
|
96
|
-
|
97
|
-
You can specify e.g. `translates :title, fallback: :any` to fall back first to the default locale, then to any other locale.
|
98
|
-
|
99
|
-
You can specify e.g. `translates :title, fallback: [:sv]` to explicitly declare fallbacks as an array of any length.
|
100
|
-
|
101
|
-
You can specify e.g. `translates :title, fallback: :i18n` to use the fallbacks from `I18n.fallbacks`.
|
102
|
-
|
103
|
-
You can override the default fallback strategy with a parameter passed to the reader: `post.title(fallback: :any)`.
|
104
|
-
|
105
|
-
If you need to declare the default locale fallback, do `post.title(fallback: :default)`.
|
106
|
-
|
107
|
-
|
108
|
-
### Overriding methods
|
109
|
-
|
110
|
-
Methods are defined in an included module, so you can just override them and call Traco's implementation with `super`:
|
111
|
-
|
112
|
-
```ruby
|
113
|
-
class Post < ActiveRecord::Base
|
114
|
-
translates :title
|
115
|
-
|
116
|
-
def title
|
117
|
-
super.reverse
|
118
|
-
end
|
119
|
-
end
|
120
|
-
```
|
121
|
-
|
122
|
-
## Installation
|
123
|
-
|
124
|
-
Add this to your `Gemfile`:
|
125
|
-
|
126
|
-
```ruby
|
127
|
-
gem "traco"
|
128
|
-
```
|
129
|
-
|
130
|
-
Then run
|
131
|
-
|
132
|
-
bundle
|
133
|
-
|
134
|
-
to install it.
|
135
|
-
|
136
|
-
|
137
|
-
## Running the tests
|
138
|
-
|
139
|
-
bundle
|
140
|
-
rake
|
141
|
-
|
142
|
-
|
143
|
-
## Benchmark
|
144
|
-
|
145
|
-
ruby benchmarks/overhead.rb
|
146
|
-
|
147
|
-
|
148
|
-
<!-- Keeping this a hidden brain dump for now.
|
149
|
-
|
150
|
-
## TODO
|
151
|
-
|
152
|
-
We've intentionally kept this simple with no features we do not need.
|
153
|
-
We'd be happy to merge additional features that others contribute.
|
154
|
-
|
155
|
-
Possible improvements to make:
|
156
|
-
|
157
|
-
* Validation that checks that at least one translation for a column exists.
|
158
|
-
* Validation that checks that every translation for a column exists.
|
159
|
-
* Scopes like `translated`, `translated_to(locale)`.
|
160
|
-
* Support for region locales, like `en-US` and `en-GB`.
|
161
|
-
|
162
|
-
-->
|
163
|
-
|
164
|
-
## Contributors
|
165
|
-
|
166
|
-
* [Henrik Nyh](http://henrik.nyh.se)
|
167
|
-
* Andrii Malyshko
|
168
|
-
* Tobias Bohwalli
|
169
|
-
* Mario Alberto Chavez
|
170
|
-
* Philip Arndt
|
171
|
-
* [PikachuEXE](https://github.com/PikachuEXE)
|
172
|
-
* Fernando Morgenstern
|
173
|
-
* Tomáš Horáček
|
174
|
-
* Joakim Kolsjö
|
175
|
-
|
176
|
-
## License
|
177
|
-
|
178
|
-
[MIT](LICENSE.txt)
|
data/Rakefile
DELETED
data/benchmarks/overhead.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# This benchmark tests how fast a Traco-wrapped attribute is
|
2
|
-
# compared to the plain Active Record attribute.
|
3
|
-
|
4
|
-
require "bundler/setup"
|
5
|
-
require "benchmark/ips"
|
6
|
-
require "active_record"
|
7
|
-
require "traco"
|
8
|
-
|
9
|
-
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
10
|
-
|
11
|
-
I18n.enforce_available_locales = false
|
12
|
-
I18n.available_locales = [ :en, :de, :sv ]
|
13
|
-
I18n.default_locale = :en
|
14
|
-
I18n.locale = :sv
|
15
|
-
|
16
|
-
COLUMNS = %w(title body long_title seo_title)
|
17
|
-
|
18
|
-
silence_stream(STDOUT) do
|
19
|
-
ActiveRecord::Schema.define(version: 0) do
|
20
|
-
create_table :posts, force: true do |t|
|
21
|
-
I18n.available_locales.each do |locale|
|
22
|
-
COLUMNS.each do |column|
|
23
|
-
t.string "#{column}_#{locale}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Post < ActiveRecord::Base
|
31
|
-
translates *COLUMNS
|
32
|
-
end
|
33
|
-
|
34
|
-
post = Post.new(title_en: "hello", title_sv: "Hej")
|
35
|
-
|
36
|
-
Benchmark.ips do |x|
|
37
|
-
x.report("activerecord") { post.title_sv }
|
38
|
-
x.report("traco") { post.title }
|
39
|
-
|
40
|
-
x.compare!
|
41
|
-
end
|
data/gemfiles/rails_4.2.gemfile
DELETED
data/gemfiles/rails_5.0.gemfile
DELETED
data/gemfiles/rails_5.1.gemfile
DELETED
data/gemfiles/rails_5.2.gemfile
DELETED
data/gemfiles/rails_6.0.gemfile
DELETED
data/gemfiles/rails_6.1.gemfile
DELETED
data/traco.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "traco/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "traco"
|
7
|
-
s.version = Traco::VERSION
|
8
|
-
s.authors = ["Henrik Nyh"]
|
9
|
-
s.email = ["henrik@barsoom.se"]
|
10
|
-
s.homepage = ""
|
11
|
-
s.summary = "Translatable columns for Rails 4.2 or better, stored in the model table itself."
|
12
|
-
s.license = "MIT"
|
13
|
-
|
14
|
-
s.files = `git ls-files`.split("\n")
|
15
|
-
s.test_files = `git ls-files -- spec/*`.split("\n")
|
16
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
-
s.require_paths = ["lib"]
|
18
|
-
|
19
|
-
s.required_ruby_version = ">= 2.3.0"
|
20
|
-
|
21
|
-
s.add_dependency "activerecord", ">= 4.2"
|
22
|
-
|
23
|
-
s.add_development_dependency "sqlite3"
|
24
|
-
|
25
|
-
s.add_development_dependency "rake"
|
26
|
-
s.add_development_dependency "rspec"
|
27
|
-
s.add_development_dependency "appraisal"
|
28
|
-
end
|