traco 3.2.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.travis.yml +22 -3
- data/Appraisals +26 -0
- data/CHANGELOG.md +28 -0
- data/README.md +9 -5
- data/gemfiles/rails_4.2.gemfile +12 -0
- data/gemfiles/rails_5.0.gemfile +12 -0
- data/gemfiles/rails_5.1.gemfile +12 -0
- data/gemfiles/rails_5.2.gemfile +11 -0
- data/gemfiles/rails_6.0.gemfile +11 -0
- data/gemfiles/rails_6.1.gemfile +11 -0
- data/lib/traco/attributes.rb +10 -1
- data/lib/traco/class_methods.rb +9 -7
- data/lib/traco/locale_fallbacks.rb +3 -1
- data/lib/traco/version.rb +1 -1
- data/spec/locale_fallbacks_spec.rb +18 -4
- data/spec/spec_helper.rb +3 -1
- data/spec/spec_helper_models.rb +5 -7
- data/spec/traco_spec.rb +38 -16
- data/traco.gemspec +5 -2
- metadata +41 -21
- data/.rvmrc +0 -1
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MmYzNmJhMjkwYjRjNmYzMThjYjk2NmFmOTYxOGNlMThkM2U0MGU0Ng==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 978a4848f6b31ac00301a8e43b89b7937a446a261031c699c3edc6cd8207d7f8
|
4
|
+
data.tar.gz: 53b5f78c80d4e5bc9a8f16aadba823e2dd258dfec8e754650c63b8e12c5ac318
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YmU5OWE3YTA5YmNhMWNkOWI0MjNmZjdjZWY5ZWNiN2E0YWVlYWMzZDY3MGUx
|
11
|
-
ODgxM2MwNGYzZjNkMjY1MGVhNmM3NjM4NjVjMGUyYTFjYWRhYmM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NzMzNzFkOGM0NjUwN2MwOGM4NDUzYTRhYTQzZDY3NWNmYzEzNmNmODFmNGQ2
|
14
|
-
ZTgzYjYwNDFiMDhiZGNiMmMyZjViNDc1YjBjMjA4NzkzYTFlMjY5MjQyNDJj
|
15
|
-
YWZiYmU2ZTIwNzE4MjFmYzJmYmYyOTlmMDJmNThjYzBlYjI3NmU=
|
6
|
+
metadata.gz: a30e150540760c82a82ed68553c298dcade15f9695fbc7af1afb7f2c443e4804233c536c2f1652c7fb3338626bfa610df339f35ea00679b43e14742647fdcc8c
|
7
|
+
data.tar.gz: 49a329d6a6b2cc7c2a6d68a21f5f9e2a2dd76327f162f8a1115c04c254ef6aaf3b287b2790e6d96b0f811873f5c46555e8d2c74143fb9bcaf678a51dc66863a4
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-r spec_helper
|
data/.travis.yml
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
-
|
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
ADDED
@@ -0,0 +1,26 @@
|
|
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
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
# Changelog
|
2
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
|
+
|
3
31
|
## 3.2.0
|
4
32
|
|
5
33
|
* Introduce e.g. `fallback: [:sv]` to explicitly specify fallbacks.
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Traco
|
2
2
|
|
3
|
-
[![Build Status](https://secure.travis-ci.org/barsoom/traco.
|
3
|
+
[![Build Status](https://secure.travis-ci.org/barsoom/traco.svg)](http://travis-ci.org/barsoom/traco)
|
4
4
|
|
5
|
-
Translatable attributes for
|
5
|
+
Translatable attributes for Ruby on Rails 4.2+, stored in the model table itself.
|
6
6
|
|
7
7
|
Inspired by Iain Hecker's [translatable_columns](https://github.com/iain/translatable_columns/).
|
8
8
|
|
@@ -46,11 +46,13 @@ You can still use your accessors like `title_sv` and `title_sv=` in forms, valid
|
|
46
46
|
|
47
47
|
`#title=`: Assigns the title to the column for the current locale, if present. Raises if the column doesn't exist.
|
48
48
|
|
49
|
+
`#title?`: Is the title present? Respects the Traco [fallback](#fallbacks) setting.
|
50
|
+
|
49
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.
|
50
52
|
|
51
53
|
`.translatable_attributes`: Returns an array like `[:title, :body]`.
|
52
54
|
|
53
|
-
`.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with
|
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:
|
54
56
|
|
55
57
|
```erb
|
56
58
|
<% Post.locale_columns(:title).each do |column| %>
|
@@ -79,7 +81,7 @@ The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]
|
|
79
81
|
|
80
82
|
`.current_locale_column(:title)`: Returns `:title_sv` if `:sv` is the current locale. Suitable for some SQL queries, such as sorting.
|
81
83
|
|
82
|
-
`.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with
|
84
|
+
`.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with current locale first, then default locale, and then alphabetically.
|
83
85
|
|
84
86
|
And the equivalent methods for `body`, of course.
|
85
87
|
|
@@ -96,6 +98,8 @@ You can specify e.g. `translates :title, fallback: :any` to fall back first to t
|
|
96
98
|
|
97
99
|
You can specify e.g. `translates :title, fallback: [:sv]` to explicitly declare fallbacks as an array of any length.
|
98
100
|
|
101
|
+
You can specify e.g. `translates :title, fallback: :i18n` to use the fallbacks from `I18n.fallbacks`.
|
102
|
+
|
99
103
|
You can override the default fallback strategy with a parameter passed to the reader: `post.title(fallback: :any)`.
|
100
104
|
|
101
105
|
If you need to declare the default locale fallback, do `post.title(fallback: :default)`.
|
@@ -120,7 +124,7 @@ end
|
|
120
124
|
Add this to your `Gemfile`:
|
121
125
|
|
122
126
|
```ruby
|
123
|
-
gem
|
127
|
+
gem "traco"
|
124
128
|
```
|
125
129
|
|
126
130
|
Then run
|
data/lib/traco/attributes.rb
CHANGED
@@ -7,6 +7,7 @@ module Traco
|
|
7
7
|
attributes.each do |attribute|
|
8
8
|
define_reader(attribute)
|
9
9
|
define_writer(attribute)
|
10
|
+
define_query(attribute)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -25,7 +26,7 @@ module Traco
|
|
25
26
|
default_fallback = #{@options.fetch(:fallback, LocaleFallbacks::DEFAULT_FALLBACK).inspect}
|
26
27
|
fallback = options.fetch(:fallback, default_fallback)
|
27
28
|
|
28
|
-
columns_to_try = self.class._locale_columns_for_attribute(:#{attribute}, fallback)
|
29
|
+
columns_to_try = self.class._locale_columns_for_attribute(:#{attribute}, fallback: fallback)
|
29
30
|
columns_to_try.each do |column|
|
30
31
|
value = send(column)
|
31
32
|
return value if value.present?
|
@@ -45,6 +46,14 @@ module Traco
|
|
45
46
|
EOM
|
46
47
|
end
|
47
48
|
|
49
|
+
def define_query(attribute)
|
50
|
+
class_eval <<-EOM, __FILE__, __LINE__ + 1
|
51
|
+
def #{attribute}?
|
52
|
+
#{attribute}.present?
|
53
|
+
end
|
54
|
+
EOM
|
55
|
+
end
|
56
|
+
|
48
57
|
# Only called once per class or inheritance chain (e.g. once
|
49
58
|
# for the superclass, not at all for subclasses). The separation
|
50
59
|
# is important if we don't want to overwrite values if running
|
data/lib/traco/class_methods.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
module Traco
|
2
2
|
module ClassMethods
|
3
3
|
def locales_for_attribute(attribute)
|
4
|
-
traco_cache(attribute, LocaleFallbacks::
|
4
|
+
traco_cache(attribute, fallback: LocaleFallbacks::ANY_FALLBACK).keys
|
5
5
|
end
|
6
6
|
|
7
7
|
def locale_columns(*attributes)
|
8
|
-
attributes.
|
9
|
-
|
10
|
-
|
8
|
+
attributes = attributes.presence || translatable_attributes
|
9
|
+
|
10
|
+
attributes.flat_map { |attribute|
|
11
|
+
_locale_columns_for_attribute(attribute, fallback: LocaleFallbacks::ANY_FALLBACK)
|
12
|
+
}
|
11
13
|
end
|
12
14
|
|
13
15
|
# Consider this method internal.
|
14
|
-
def _locale_columns_for_attribute(attribute, fallback)
|
15
|
-
traco_cache(attribute, fallback).values
|
16
|
+
def _locale_columns_for_attribute(attribute, fallback:)
|
17
|
+
traco_cache(attribute, fallback: fallback).values
|
16
18
|
end
|
17
19
|
|
18
20
|
def current_locale_column(attribute)
|
@@ -52,7 +54,7 @@ module Traco
|
|
52
54
|
# }
|
53
55
|
# }
|
54
56
|
# }
|
55
|
-
def traco_cache(attribute, fallback)
|
57
|
+
def traco_cache(attribute, fallback:)
|
56
58
|
cache = @traco_cache ||= {}
|
57
59
|
per_locale_cache = cache[I18n.locale] ||= {}
|
58
60
|
per_attribute_cache = per_locale_cache[attribute] ||= {}
|
@@ -7,6 +7,7 @@ module Traco
|
|
7
7
|
ANY_FALLBACK = :any,
|
8
8
|
NO_FALLBACK = false,
|
9
9
|
DEFAULT_FIRST_FALLBACK = :default_first,
|
10
|
+
I18N_FALLBACK = :i18n,
|
10
11
|
]
|
11
12
|
|
12
13
|
attr_reader :fallback_option
|
@@ -26,7 +27,8 @@ module Traco
|
|
26
27
|
when ANY_FALLBACK then [ current_locale, @default_locale, *@available_locales ].uniq
|
27
28
|
when NO_FALLBACK then [ current_locale ]
|
28
29
|
when DEFAULT_FIRST_FALLBACK then [ @default_locale, *@available_locales ].uniq
|
29
|
-
when
|
30
|
+
when I18N_FALLBACK then I18n.fallbacks[current_locale]
|
31
|
+
when Array then [ current_locale, *fallback_option ]
|
30
32
|
else raise "Unknown fallback." # Should never get here.
|
31
33
|
end
|
32
34
|
end
|
data/lib/traco/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require "spec_helper"
|
2
1
|
require "traco/locale_fallbacks"
|
3
2
|
|
4
|
-
describe Traco::LocaleFallbacks do
|
3
|
+
RSpec.describe Traco::LocaleFallbacks do
|
5
4
|
describe ".new" do
|
6
5
|
it "raises ArgumentError if an unknown argument passed in" do
|
7
6
|
expect { Traco::LocaleFallbacks.new(:foo) }.to raise_error(ArgumentError)
|
@@ -36,9 +35,9 @@ describe Traco::LocaleFallbacks do
|
|
36
35
|
end
|
37
36
|
|
38
37
|
context "with an explicit list of locales" do
|
39
|
-
it "returns only those locales" do
|
38
|
+
it "returns only those locales, after the current one" do
|
40
39
|
subject = Traco::LocaleFallbacks.new([ :en ])
|
41
|
-
expect(subject[:sv]).to eq [ :en ]
|
40
|
+
expect(subject[:sv]).to eq [ :sv, :en ]
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
@@ -51,5 +50,20 @@ describe Traco::LocaleFallbacks do
|
|
51
50
|
expect(subject[:sv]).to eq [ :uk, :de, :en, :sv ]
|
52
51
|
end
|
53
52
|
end
|
53
|
+
|
54
|
+
context "with the ':i18n' option" do
|
55
|
+
it "returns what is configured as a I18n fallback" do
|
56
|
+
I18n.fallbacks = I18n::Locale::Fallbacks.new(
|
57
|
+
en: [ :en, :uk, :de, :sv ],
|
58
|
+
uk: [ :uk, :en, :de, :sv ],
|
59
|
+
de: [ :de, :uk, :en, :sv ],
|
60
|
+
sv: [ :sv, :en, :uk, :de ],
|
61
|
+
)
|
62
|
+
|
63
|
+
subject = Traco::LocaleFallbacks.new(:i18n)
|
64
|
+
expect(subject[:sv]).to eq [ :sv, :en, :uk, :de ]
|
65
|
+
expect(subject[:de]).to eq [ :de, :uk, :en, :sv ]
|
66
|
+
end
|
67
|
+
end
|
54
68
|
end
|
55
69
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require "i18n"
|
2
2
|
|
3
3
|
RSpec.configure do |config|
|
4
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
4
|
config.filter_run focus: true
|
6
5
|
config.run_all_when_everything_filtered = true
|
6
|
+
config.disable_monkey_patching!
|
7
7
|
end
|
8
8
|
|
9
9
|
I18n.enforce_available_locales = false
|
10
|
+
|
11
|
+
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
|
data/spec/spec_helper_models.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
RSpec.configure do |config|
|
2
|
-
config.before
|
2
|
+
config.before do
|
3
3
|
# Clear class state before each spec.
|
4
4
|
Object.send(:remove_const, "Post")
|
5
5
|
Object.send(:remove_const, "SubPost")
|
@@ -19,12 +19,10 @@ require "app/post.rb"
|
|
19
19
|
|
20
20
|
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
t.string :body_sv, :body_en, :body_pt_br
|
27
|
-
end
|
22
|
+
ActiveRecord::Schema.define(version: 0) do
|
23
|
+
create_table :posts, force: true do |t|
|
24
|
+
t.string :title_sv, :title_en, :title_pt_br, :title_de
|
25
|
+
t.string :body_sv, :body_en, :body_pt_br, :body_de
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
data/spec/traco_spec.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "spec_helper"
|
4
3
|
require "spec_helper_models"
|
5
4
|
require "traco"
|
6
5
|
|
7
|
-
describe Traco, ".split_localized_column" do
|
6
|
+
RSpec.describe Traco, ".split_localized_column" do
|
8
7
|
subject { described_class }
|
9
8
|
|
10
9
|
it "returns attribute and locale" do
|
@@ -24,7 +23,7 @@ describe Traco, ".split_localized_column" do
|
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
|
-
describe ActiveRecord::Base, ".translates" do
|
26
|
+
RSpec.describe ActiveRecord::Base, ".translates" do
|
28
27
|
it "is available" do
|
29
28
|
expect(Post).to respond_to :translates
|
30
29
|
end
|
@@ -57,7 +56,7 @@ describe ActiveRecord::Base, ".translates" do
|
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
describe Post, ".translatable_attributes" do
|
59
|
+
RSpec.describe Post, ".translatable_attributes" do
|
61
60
|
before do
|
62
61
|
Post.translates :title
|
63
62
|
end
|
@@ -77,15 +76,15 @@ describe Post, ".translatable_attributes" do
|
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
|
-
describe Post, ".locales_for_attribute" do
|
79
|
+
RSpec.describe Post, ".locales_for_attribute" do
|
81
80
|
before do
|
82
81
|
Post.translates :title
|
83
82
|
I18n.default_locale = :"pt-BR"
|
84
83
|
I18n.locale = :en
|
85
84
|
end
|
86
85
|
|
87
|
-
it "lists the locales for that attribute,
|
88
|
-
expect(Post.locales_for_attribute(:title)).to eq [ :"pt-BR", :
|
86
|
+
it "lists the locales for that attribute, current locale first, then default locale, and then alphabetically" do
|
87
|
+
expect(Post.locales_for_attribute(:title)).to eq [ :en, :"pt-BR", :de, :sv ]
|
89
88
|
end
|
90
89
|
|
91
90
|
it "doesn't include a locale if there's no corresponding column for it" do
|
@@ -95,16 +94,16 @@ describe Post, ".locales_for_attribute" do
|
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
98
|
-
describe Post, ".locale_columns" do
|
97
|
+
RSpec.describe Post, ".locale_columns" do
|
99
98
|
before do
|
100
99
|
Post.translates :title
|
101
100
|
I18n.default_locale = :"pt-BR"
|
102
101
|
I18n.locale = :en
|
103
102
|
end
|
104
103
|
|
105
|
-
it "lists the columns-with-locale for that attribute,
|
104
|
+
it "lists the columns-with-locale for that attribute, current locale first, then default locale, and then alphabetically" do
|
106
105
|
expect(Post.locale_columns(:title)).to eq [
|
107
|
-
:title_pt_br, :
|
106
|
+
:title_en, :title_pt_br, :title_de, :title_sv,
|
108
107
|
]
|
109
108
|
end
|
110
109
|
|
@@ -118,13 +117,19 @@ describe Post, ".locale_columns" do
|
|
118
117
|
Post.translates :body
|
119
118
|
|
120
119
|
expect(Post.locale_columns(:body, :title)).to eq [
|
121
|
-
:body_pt_br, :
|
122
|
-
:title_pt_br, :
|
120
|
+
:body_en, :body_pt_br, :body_de, :body_sv,
|
121
|
+
:title_en, :title_pt_br, :title_de, :title_sv,
|
122
|
+
]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns the columns of all translated attributes if no params are supplied" do
|
126
|
+
expect(Post.locale_columns).to eq [
|
127
|
+
:title_en, :title_pt_br, :title_de, :title_sv
|
123
128
|
]
|
124
129
|
end
|
125
130
|
end
|
126
131
|
|
127
|
-
describe Post, ".current_locale_column" do
|
132
|
+
RSpec.describe Post, ".current_locale_column" do
|
128
133
|
before do
|
129
134
|
Post.translates :title
|
130
135
|
end
|
@@ -140,7 +145,7 @@ describe Post, ".current_locale_column" do
|
|
140
145
|
end
|
141
146
|
end
|
142
147
|
|
143
|
-
describe Post, "#title" do
|
148
|
+
RSpec.describe Post, "#title" do
|
144
149
|
let(:post) {
|
145
150
|
Post.new(title_sv: "Hej", title_en: "Halloa", title_pt_br: "Olá")
|
146
151
|
}
|
@@ -271,7 +276,7 @@ describe Post, "#title" do
|
|
271
276
|
end
|
272
277
|
end
|
273
278
|
|
274
|
-
describe Post, "#title=" do
|
279
|
+
RSpec.describe Post, "#title=" do
|
275
280
|
before do
|
276
281
|
Post.translates :title
|
277
282
|
end
|
@@ -298,7 +303,24 @@ describe Post, "#title=" do
|
|
298
303
|
end
|
299
304
|
end
|
300
305
|
|
301
|
-
describe Post, "
|
306
|
+
RSpec.describe Post, "#title?" do
|
307
|
+
before do
|
308
|
+
Post.translates :title
|
309
|
+
I18n.locale = :sv
|
310
|
+
I18n.default_locale = :en
|
311
|
+
end
|
312
|
+
|
313
|
+
it "is true if the title is present" do
|
314
|
+
post = Post.new(title_sv: "", title_en: " ", title_pt_br: nil)
|
315
|
+
expect(post.title?).to be false
|
316
|
+
|
317
|
+
post.title_en = "Hello"
|
318
|
+
|
319
|
+
expect(post.title?).to be true
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
RSpec.describe Post, ".human_attribute_name" do
|
302
324
|
before do
|
303
325
|
Post.translates :title
|
304
326
|
I18n.locale = :sv
|
data/traco.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Henrik Nyh"]
|
9
9
|
s.email = ["henrik@barsoom.se"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = "Translatable columns for Rails
|
11
|
+
s.summary = "Translatable columns for Rails 4.2 or better, stored in the model table itself."
|
12
12
|
s.license = "MIT"
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
@@ -16,10 +16,13 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.
|
19
|
+
s.required_ruby_version = ">= 2.3.0"
|
20
|
+
|
21
|
+
s.add_dependency "activerecord", ">= 4.2"
|
20
22
|
|
21
23
|
s.add_development_dependency "sqlite3"
|
22
24
|
|
23
25
|
s.add_development_dependency "rake"
|
24
26
|
s.add_development_dependency "rspec"
|
27
|
+
s.add_development_dependency "appraisal"
|
25
28
|
end
|
metadata
CHANGED
@@ -1,69 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
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: '
|
26
|
+
version: '4.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
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
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: appraisal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
description:
|
@@ -73,15 +87,22 @@ executables: []
|
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .
|
78
|
-
- .travis.yml
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Appraisals
|
79
94
|
- CHANGELOG.md
|
80
95
|
- Gemfile
|
81
96
|
- LICENSE.txt
|
82
97
|
- README.md
|
83
98
|
- Rakefile
|
84
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
|
85
106
|
- lib/traco.rb
|
86
107
|
- lib/traco/attributes.rb
|
87
108
|
- lib/traco/class_methods.rb
|
@@ -105,20 +126,19 @@ require_paths:
|
|
105
126
|
- lib
|
106
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
128
|
requirements:
|
108
|
-
- -
|
129
|
+
- - ">="
|
109
130
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
131
|
+
version: 2.3.0
|
111
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
133
|
requirements:
|
113
|
-
- -
|
134
|
+
- - ">="
|
114
135
|
- !ruby/object:Gem::Version
|
115
136
|
version: '0'
|
116
137
|
requirements: []
|
117
|
-
|
118
|
-
rubygems_version: 2.2.2
|
138
|
+
rubygems_version: 3.1.4
|
119
139
|
signing_key:
|
120
140
|
specification_version: 4
|
121
|
-
summary: Translatable columns for Rails
|
141
|
+
summary: Translatable columns for Rails 4.2 or better, stored in the model table itself.
|
122
142
|
test_files:
|
123
143
|
- spec/app/post.rb
|
124
144
|
- spec/app/sv.yml
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm ruby-1.9.3-p194-falcon@traco --create
|