traco 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDRjODY3Yjg3NmE2MmJiZWQ3NjBhNGE2MDJhNDIwM2ZhNjY4MjNjOQ==
5
+ data.tar.gz: !binary |-
6
+ MzIxZjkyY2JiODc3YzU3NDhmYWNiNzI2ODMzMjI5MWY4ZmQ2YmRhMQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTNhZjQyMzEyZTgyNGQwYzg1NTgyZWIzYTc2MjJlZWUwYTNhMGY5OTkwMWQ3
10
+ YzNhMWEyNDhiNjE0ZjYxYTc5N2IzMjljOWEyOGVlNDVhZTZhZTljOWE2MTM2
11
+ NzgwYTk3OGNjY2Y3ZWY0YTcwNWQxMzg2YWI4MWZmMDBiZDM5YzA=
12
+ data.tar.gz: !binary |-
13
+ YTQ4NmNhMDMxZmI2NTQxMzBkMWYzNDc1MGU0OTgzODEyYTUzZTE3MTAyOTFi
14
+ NDhlZDg5MzEzZTVjZThlYmU3NzExYTZmZjM1ZTMwYTQxOWQyMTE1ZTMxZjYw
15
+ NGM5ZDVlYTViYTlmMDE4MmI3YzgzMGQ2Y2U5YmQyYTgxMGI0NGI=
data/README.md CHANGED
@@ -97,6 +97,8 @@ end
97
97
 
98
98
  then `#title` will return `nil` if there is no translation in the current locale, instead of falling back to the default locale.
99
99
 
100
+ If you still want to fall back in some cases, call `post.title(fallback: true)`.
101
+
100
102
 
101
103
  ### Overriding methods
102
104
 
@@ -144,7 +146,6 @@ Possible improvements to make:
144
146
 
145
147
  * Validation that checks that at least one translation for a column exists.
146
148
  * Validation that checks that every translation for a column exists.
147
- * Option to disable fallback.
148
149
  * Scopes like `translated`, `translated_to(locale)`.
149
150
  * Support for region locales, like `en-US` and `en-GB`.
150
151
 
@@ -49,9 +49,11 @@ module Traco
49
49
  end
50
50
 
51
51
  def define_localized_reader(attribute, options)
52
- fallback = options.fetch(:fallback, true)
52
+ default_fallback = options.fetch(:fallback, true)
53
+
54
+ custom_define_method(attribute) do |method_opts = {}|
55
+ fallback = method_opts.fetch(:fallback, default_fallback)
53
56
 
54
- custom_define_method(attribute) do
55
57
  @localized_readers ||= {}
56
58
  @localized_readers[attribute] ||= Traco::LocalizedReader.new(self, attribute, fallback: fallback)
57
59
  @localized_readers[attribute].value
data/lib/traco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Traco
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
data/spec/traco_spec.rb CHANGED
@@ -111,6 +111,12 @@ describe Post, "#title" do
111
111
  post.title.should be_nil
112
112
  end
113
113
 
114
+ it "does not fall back if called with fallback: false" do
115
+ I18n.locale = :sv
116
+ post.title_sv = ""
117
+ post.title(fallback: false).should be_nil
118
+ end
119
+
114
120
  it "returns nil if all are blank" do
115
121
  post.title_sv = " "
116
122
  post.title_en = ""
@@ -136,7 +142,7 @@ describe Post, "#title" do
136
142
  post.title.should == "title"
137
143
  post.body.should == "body"
138
144
  end
139
-
145
+
140
146
  it "reflects locale change" do
141
147
  post.title.should == "Hej"
142
148
  I18n.locale = :en
@@ -145,7 +151,7 @@ describe Post, "#title" do
145
151
  post.title.should == "Hej"
146
152
  end
147
153
 
148
- context "with fallback: false" do
154
+ context "when the translation was defined with fallback: false" do
149
155
  let(:post) {
150
156
  Post.new(title_sv: "Hej", title_en: "Halloa")
151
157
  }
@@ -165,6 +171,11 @@ describe Post, "#title" do
165
171
  post.title_sv = " "
166
172
  post.title.should be_nil
167
173
  end
174
+
175
+ it "still falls back if called with fallback: true" do
176
+ I18n.locale = :ru
177
+ post.title(fallback: true).should == "Halloa"
178
+ end
168
179
  end
169
180
  end
170
181
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traco
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
5
- prerelease:
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Henrik Nyh
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-13 00:00:00.000000000 Z
11
+ date: 2014-02-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -102,33 +93,26 @@ files:
102
93
  - traco.gemspec
103
94
  homepage: ''
104
95
  licenses: []
96
+ metadata: {}
105
97
  post_install_message:
106
98
  rdoc_options: []
107
99
  require_paths:
108
100
  - lib
109
101
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
102
  requirements:
112
103
  - - ! '>='
113
104
  - !ruby/object:Gem::Version
114
105
  version: '0'
115
- segments:
116
- - 0
117
- hash: -4140218999015648570
118
106
  required_rubygems_version: !ruby/object:Gem::Requirement
119
- none: false
120
107
  requirements:
121
108
  - - ! '>='
122
109
  - !ruby/object:Gem::Version
123
110
  version: '0'
124
- segments:
125
- - 0
126
- hash: -4140218999015648570
127
111
  requirements: []
128
112
  rubyforge_project:
129
- rubygems_version: 1.8.24
113
+ rubygems_version: 2.2.1
130
114
  signing_key:
131
- specification_version: 3
115
+ specification_version: 4
132
116
  summary: Translatable columns for Rails 3 or better, stored in the model table itself.
133
117
  test_files:
134
118
  - spec/app/post.rb