traco 3.2.1 → 4.0.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 +5 -13
- data/.travis.yml +8 -3
- data/CHANGELOG.md +12 -0
- data/README.md +4 -2
- data/lib/traco/attributes.rb +10 -1
- data/lib/traco/class_methods.rb +5 -5
- data/lib/traco/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/spec_helper_models.rb +4 -6
- data/spec/traco_spec.rb +17 -0
- data/traco.gemspec +2 -0
- metadata +16 -17
- data/.rvmrc +0 -1
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTI3YWIxYmRjNDQ5MmIxNWIyNmI3NGFjMWEwY2FiZWEwMjNiMWFiOA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9060bececc2eb2a4f5bf6fd798f1b6c16523dd21
|
4
|
+
data.tar.gz: a32a98d4c86f84fc94430cf11ab660fe8993c973
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OTA3ZDY1ZWMxZDFmMmFkMGM4NTE4Y2I0ZjM1NTY2ODFmY2UwMzY0ZjYwZTQy
|
11
|
-
YWM1N2U2OTkyNWY3YTM1OTU2NDNlMjNlNjczMTBjYmZjMzU2Yzk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OTUyOGE2M2E0MTM3ODVhMjg1MTA3MDkzNDU3YmUwOTZhMWM5Yjg0MDJhNDU2
|
14
|
-
YzVjM2JhM2E3ZjBhOWJmZTUzOWI2NWIxZTljZjA4MDUxMWUyMzkyMTUyNmI5
|
15
|
-
NmRiOTdhNzA2NmU3OTVmZmM2N2U3MWQzN2NiMmIyOGUyOTU5MDg=
|
6
|
+
metadata.gz: 23d5789232d16fa41117707e3502027d4d04328adee5bf8853213dd128ed26badb14f3ad03afbe073424c58d39eb98b46be78998f87d1bf000aa0f0f0d6f9bb5
|
7
|
+
data.tar.gz: c9461bd93ed5118f51da0862ee929f93df74964c7c56371ca60d88faba043e535b632fcc504e3351c50958f14f130ca2456ad32a06652e4f3dcf5c4ca5a98b6a
|
data/.travis.yml
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.1
|
4
|
-
- 2.
|
5
|
-
-
|
3
|
+
- 2.5.1
|
4
|
+
- 2.4.4
|
5
|
+
- 2.3.0
|
6
|
+
|
7
|
+
# Avoid some errors, and speed things up:
|
8
|
+
# https://github.com/bundler/bundler/issues/3558#issuecomment-171347979
|
9
|
+
# https://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
10
|
+
sudo: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 4.0.0
|
4
|
+
|
5
|
+
* Drop support for end-of-lifed Ruby 2.1 and 2.2.
|
6
|
+
|
7
|
+
## 3.3.0
|
8
|
+
|
9
|
+
* Traco now automatically adds query methods, e.g. `Item#title?` when `title` is translated.
|
10
|
+
|
11
|
+
## 3.2.2
|
12
|
+
|
13
|
+
* Internal cleanup.
|
14
|
+
|
3
15
|
## 3.2.1
|
4
16
|
|
5
17
|
* Bugfix: with `fallback: [:sv]`, always look at current locale before any fallbacks.
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/barsoom/traco)
|
4
4
|
|
5
|
-
Translatable attributes for
|
5
|
+
Translatable attributes for Ruby on Rails, 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,6 +46,8 @@ 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]`.
|
@@ -120,7 +122,7 @@ end
|
|
120
122
|
Add this to your `Gemfile`:
|
121
123
|
|
122
124
|
```ruby
|
123
|
-
gem
|
125
|
+
gem "traco"
|
124
126
|
```
|
125
127
|
|
126
128
|
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,18 @@
|
|
1
1
|
module Traco
|
2
2
|
module ClassMethods
|
3
3
|
def locales_for_attribute(attribute)
|
4
|
-
traco_cache(attribute, LocaleFallbacks::DEFAULT_FIRST_FALLBACK).keys
|
4
|
+
traco_cache(attribute, fallback: LocaleFallbacks::DEFAULT_FIRST_FALLBACK).keys
|
5
5
|
end
|
6
6
|
|
7
7
|
def locale_columns(*attributes)
|
8
8
|
attributes.each_with_object([]) do |attribute, columns|
|
9
|
-
columns.concat(_locale_columns_for_attribute(attribute, LocaleFallbacks::DEFAULT_FIRST_FALLBACK))
|
9
|
+
columns.concat(_locale_columns_for_attribute(attribute, fallback: LocaleFallbacks::DEFAULT_FIRST_FALLBACK))
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
# Consider this method internal.
|
14
|
-
def _locale_columns_for_attribute(attribute, fallback)
|
15
|
-
traco_cache(attribute, fallback).values
|
14
|
+
def _locale_columns_for_attribute(attribute, fallback:)
|
15
|
+
traco_cache(attribute, fallback: fallback).values
|
16
16
|
end
|
17
17
|
|
18
18
|
def current_locale_column(attribute)
|
@@ -52,7 +52,7 @@ module Traco
|
|
52
52
|
# }
|
53
53
|
# }
|
54
54
|
# }
|
55
|
-
def traco_cache(attribute, fallback)
|
55
|
+
def traco_cache(attribute, fallback:)
|
56
56
|
cache = @traco_cache ||= {}
|
57
57
|
per_locale_cache = cache[I18n.locale] ||= {}
|
58
58
|
per_attribute_cache = per_locale_cache[attribute] ||= {}
|
data/lib/traco/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/spec_helper_models.rb
CHANGED
@@ -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
|
25
|
+
t.string :body_sv, :body_en, :body_pt_br
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
data/spec/traco_spec.rb
CHANGED
@@ -298,6 +298,23 @@ describe Post, "#title=" do
|
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
301
|
+
describe Post, "#title?" do
|
302
|
+
before do
|
303
|
+
Post.translates :title
|
304
|
+
I18n.locale = :sv
|
305
|
+
I18n.default_locale = :en
|
306
|
+
end
|
307
|
+
|
308
|
+
it "is true if the title is present" do
|
309
|
+
post = Post.new(title_sv: "", title_en: " ", title_pt_br: nil)
|
310
|
+
expect(post.title?).to be false
|
311
|
+
|
312
|
+
post.title_en = "Hello"
|
313
|
+
|
314
|
+
expect(post.title?).to be true
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
301
318
|
describe Post, ".human_attribute_name" do
|
302
319
|
before do
|
303
320
|
Post.translates :title
|
data/traco.gemspec
CHANGED
@@ -16,6 +16,8 @@ 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.required_ruby_version = ">= 2.3.0"
|
20
|
+
|
19
21
|
s.add_dependency "activerecord", ">= 3.0"
|
20
22
|
|
21
23
|
s.add_development_dependency "sqlite3"
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.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: 2018-07-11 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
19
|
version: '3.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
26
|
version: '3.0'
|
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
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description:
|
@@ -73,9 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .
|
78
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
79
78
|
- CHANGELOG.md
|
80
79
|
- Gemfile
|
81
80
|
- LICENSE.txt
|
@@ -105,17 +104,17 @@ require_paths:
|
|
105
104
|
- lib
|
106
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
106
|
requirements:
|
108
|
-
- -
|
107
|
+
- - ">="
|
109
108
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
109
|
+
version: 2.3.0
|
111
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
111
|
requirements:
|
113
|
-
- -
|
112
|
+
- - ">="
|
114
113
|
- !ruby/object:Gem::Version
|
115
114
|
version: '0'
|
116
115
|
requirements: []
|
117
116
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.6.11
|
119
118
|
signing_key:
|
120
119
|
specification_version: 4
|
121
120
|
summary: Translatable columns for Rails 3 or better, stored in the model table itself.
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm ruby-1.9.3-p194-falcon@traco --create
|