armot 0.3.3 → 0.3.4
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.
- data/README.md +6 -0
- data/lib/armot/active_record_extensions.rb +10 -4
- data/lib/armot/version.rb +1 -1
- data/test/armot_test.rb +22 -0
- data/test/test_helper.rb +9 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -200,6 +200,12 @@ armotized attributes using the `:all` keyword:
|
|
200
200
|
define_localized_accessors_for :all
|
201
201
|
end
|
202
202
|
|
203
|
+
You can also explicitly set the locales in which the accessors should be
|
204
|
+
defined, using this syntax:
|
205
|
+
|
206
|
+
class Post
|
207
|
+
define_localized_accessors_for :all, :locales => [:klingon, :pt]
|
208
|
+
end
|
203
209
|
|
204
210
|
|
205
211
|
Development with armot
|
@@ -21,10 +21,16 @@ module Armot
|
|
21
21
|
end
|
22
22
|
|
23
23
|
define_method :reload_localized_accessors_for do |*localizable_attributes|
|
24
|
-
localizable_attributes = armotized_attributes if localizable_attributes ==
|
24
|
+
localizable_attributes = armotized_attributes if localizable_attributes.first == :all
|
25
|
+
|
26
|
+
locales_to_define = if localizable_attributes.last.is_a?(Hash) && localizable_attributes.last[:locales]
|
27
|
+
localizable_attributes.last[:locales]
|
28
|
+
else
|
29
|
+
I18n.available_locales
|
30
|
+
end
|
25
31
|
|
26
32
|
localizable_attributes.each do |attr|
|
27
|
-
|
33
|
+
locales_to_define.each do |locale|
|
28
34
|
next if respond_to?(:"#{attr}_#{locale}")
|
29
35
|
define_method "#{attr}_#{locale}" do
|
30
36
|
armot_wrap_in_locale(locale) do
|
@@ -102,13 +108,13 @@ module Armot
|
|
102
108
|
define_method :"#{attribute}" do
|
103
109
|
return armot_attributes[I18n.locale]["#{attribute}"] if armot_attributes[I18n.locale]["#{attribute}"]
|
104
110
|
|
105
|
-
if armot_attributes.any?
|
111
|
+
if armot_attributes.any? && I18n.respond_to?(:fallbacks)
|
106
112
|
I18n.fallbacks[I18n.locale].each do |fallback|
|
107
113
|
return armot_attributes[fallback]["#{attribute}"] if armot_attributes[fallback]["#{attribute}"]
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
111
|
-
if persisted?
|
117
|
+
if persisted? && I18n.respond_to?(:fallbacks)
|
112
118
|
trans = I18n.t "#{attribute}_#{id}", :scope => "armot.#{self.class.to_s.underscore.pluralize}.#{attribute}", :default => Armot.token
|
113
119
|
return trans if trans != Armot.token
|
114
120
|
end
|
data/lib/armot/version.rb
CHANGED
data/test/armot_test.rb
CHANGED
@@ -510,4 +510,26 @@ class ArmotTest < ActiveSupport::TestCase
|
|
510
510
|
FuzzBar.reload_localized_accessors_for :title
|
511
511
|
assert_equal true, foo.respond_to?(:title_sk)
|
512
512
|
end
|
513
|
+
|
514
|
+
test "should work if the I18n backend has not fallbacks" do
|
515
|
+
with_no_method(I18n.singleton_class, :fallbacks) do
|
516
|
+
assert_equal false, I18n.respond_to?(:fallbacks)
|
517
|
+
|
518
|
+
post = Post.last
|
519
|
+
I18n.locale = :pt
|
520
|
+
assert_equal nil, post.title
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
test "define_localized_accessors_for with specific locales" do
|
525
|
+
class FuzzBarTwo < Post
|
526
|
+
define_localized_accessors_for :title, :locales => [:love, :hate]
|
527
|
+
end
|
528
|
+
|
529
|
+
foo = FuzzBarTwo.new
|
530
|
+
assert_equal true, foo.respond_to?(:title_love)
|
531
|
+
assert_equal true, foo.respond_to?(:"title_love=")
|
532
|
+
assert_equal true, foo.respond_to?(:title_hate)
|
533
|
+
assert_equal true, foo.respond_to?(:"title_hate=")
|
534
|
+
end
|
513
535
|
end
|
data/test/test_helper.rb
CHANGED
@@ -69,3 +69,12 @@ def count_query_updates_for(clazz)
|
|
69
69
|
logger.close
|
70
70
|
log_stream.string.scan(/UPDATE \"#{clazz.constantize.table_name}\"/).size
|
71
71
|
end
|
72
|
+
|
73
|
+
def with_no_method(target, name)
|
74
|
+
target.send(:alias_method, :method_backup, name)
|
75
|
+
target.send(:remove_method, name)
|
76
|
+
yield
|
77
|
+
|
78
|
+
ensure
|
79
|
+
target.send(:alias_method, name, :method_backup)
|
80
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: armot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n-active_record
|