globalize-accessors 0.1.2 → 0.1.3
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/globalize-accessors.rb +5 -6
- data/lib/globalize-accessors/version.rb +1 -1
- data/readme.md +1 -1
- data/test/globalize_accessors_test.rb +30 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb81591d0892a68040b226ca603d12e538aaa430
|
4
|
+
data.tar.gz: 4b4e3a579c5eff87286b320b7177f86fa8313b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c74b3362d3fcadeb5999bd19a55ff8695cb421efa1553f08a6dedf2c8375d19956a4cba63cdaf393e4edcf6cd65cf276e9ed9096dd3533498075e74d71fa50
|
7
|
+
data.tar.gz: 52283201db4341df4b3bb5bef75f77be4d1247a8ccff3f29cd3e79968f9e631b9089e75634f370ef857bbd5fb6ecc442d0b4baf2d1952ad7b4c393ca37c1736e
|
data/lib/globalize-accessors.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'globalize'
|
2
2
|
|
3
3
|
module Globalize::Accessors
|
4
|
-
attr_reader :globalize_locales
|
5
|
-
attr_reader :globalize_attribute_names
|
6
|
-
|
7
4
|
def globalize_accessors(options = {})
|
8
5
|
options.reverse_merge!(:locales => I18n.available_locales, :attributes => translated_attribute_names)
|
9
|
-
|
10
|
-
|
6
|
+
class_attribute :globalize_locales, :globalize_attribute_names, :instance_writer => false
|
7
|
+
|
8
|
+
self.globalize_locales = options[:locales]
|
9
|
+
self.globalize_attribute_names = []
|
11
10
|
|
12
11
|
each_attribute_and_locale(options) do |attr_name, locale|
|
13
12
|
define_accessors(attr_name, locale)
|
@@ -39,7 +38,7 @@ module Globalize::Accessors
|
|
39
38
|
if respond_to?(:accessible_attributes) && accessible_attributes.include?(attr_name)
|
40
39
|
attr_accessible :"#{localized_attr_name}"
|
41
40
|
end
|
42
|
-
|
41
|
+
self.globalize_attribute_names << localized_attr_name.to_sym
|
43
42
|
end
|
44
43
|
|
45
44
|
def each_attribute_and_locale(options)
|
data/readme.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Globalize Accessors [](https://travis-ci.org/globalize/globalize-accessors)
|
1
|
+
# Globalize Accessors [](https://travis-ci.org/globalize/globalize-accessors)
|
2
2
|
|
3
3
|
## Introduction
|
4
4
|
|
@@ -13,11 +13,21 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
13
13
|
globalize_accessors :locales => [:pl], :attributes => [:name]
|
14
14
|
end
|
15
15
|
|
16
|
-
class
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
class UnitInherited < UnitTranslatedWithOptions
|
17
|
+
end
|
18
|
+
|
19
|
+
class UnitInheritedWithOptions < ActiveRecord::Base
|
20
|
+
translates :color
|
21
|
+
globalize_accessors :locales => [:de], :attributes => [:color]
|
22
|
+
end
|
23
|
+
|
24
|
+
if ENV['RAILS_3']
|
25
|
+
class UnitWithAttrAccessible < ActiveRecord::Base
|
26
|
+
self.table_name = :units
|
27
|
+
attr_accessible :name
|
28
|
+
translates :name, :title
|
29
|
+
globalize_accessors
|
30
|
+
end
|
21
31
|
end
|
22
32
|
|
23
33
|
class UnitWithDashedLocales < ActiveRecord::Base
|
@@ -141,4 +151,19 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
141
151
|
test "globalize attribute names on class with attributes specified in options" do
|
142
152
|
assert_equal [:name_pl], UnitTranslatedWithOptions.globalize_attribute_names
|
143
153
|
end
|
154
|
+
|
155
|
+
test "inherit globalize locales and attributes" do
|
156
|
+
assert_equal [:name_pl], UnitInherited.globalize_attribute_names
|
157
|
+
assert_equal [:pl], UnitInherited.globalize_locales
|
158
|
+
end
|
159
|
+
|
160
|
+
test "overwrite inherited globalize locales and attributes" do
|
161
|
+
assert_equal [:color_de], UnitInheritedWithOptions.globalize_attribute_names
|
162
|
+
assert_equal [:de], UnitInheritedWithOptions.globalize_locales
|
163
|
+
end
|
164
|
+
|
165
|
+
test "instance cannot set globalize locales or attributes" do
|
166
|
+
assert_raise(NoMethodError) { Unit.new.globalize_attribute_names = [:name] }
|
167
|
+
assert_raise(NoMethodError) { Unit.new.globalize_locales = [:en, :de] }
|
168
|
+
end
|
144
169
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalize-accessors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Stachewicz
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-12-
|
15
|
+
date: 2013-12-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: globalize
|