globalize-accessors 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebf9c4a52aea9e8ff546ee109e2ca3cf1a7641e7
4
- data.tar.gz: c2ee6386a210d5a63595901e61118ec3be0e9e4d
3
+ metadata.gz: fb81591d0892a68040b226ca603d12e538aaa430
4
+ data.tar.gz: 4b4e3a579c5eff87286b320b7177f86fa8313b1f
5
5
  SHA512:
6
- metadata.gz: 2d0d5c1297a0ecd11cdc3d31c2e142170e06744966c073eebbfbb0caf87b1bfe6ff11e3f64a28689e94bf7e92ece20db164136195890a4ade450a9b05e6d6b46
7
- data.tar.gz: 71cc829fdebf3540953aa07fd1c568d9f441edd7309b291f3ac5184111de19402d516f164ea6d8d46cd3ca921d3f079025079aca4119154da4f4662296f10b9a
6
+ metadata.gz: 89c74b3362d3fcadeb5999bd19a55ff8695cb421efa1553f08a6dedf2c8375d19956a4cba63cdaf393e4edcf6cd65cf276e9ed9096dd3533498075e74d71fa50
7
+ data.tar.gz: 52283201db4341df4b3bb5bef75f77be4d1247a8ccff3f29cd3e79968f9e631b9089e75634f370ef857bbd5fb6ecc442d0b4baf2d1952ad7b4c393ca37c1736e
@@ -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
- @globalize_locales = options[:locales]
10
- @globalize_attribute_names = []
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
- @globalize_attribute_names << localized_attr_name.to_sym
41
+ self.globalize_attribute_names << localized_attr_name.to_sym
43
42
  end
44
43
 
45
44
  def each_attribute_and_locale(options)
@@ -1,3 +1,3 @@
1
1
  module GlobalizeAccessors
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # Globalize Accessors [![Build Status](https://travis-ci.org/globalize/globalize-accessors.png)](https://travis-ci.org/globalize/globalize-accessors)
1
+ # Globalize Accessors [![Build Status](https://travis-ci.org/globalize/globalize-accessors.png?branch=master)](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 UnitWithAttrAccessible < ActiveRecord::Base
17
- self.table_name = :units
18
- attr_accessible :name if ENV['RAILS_3']
19
- translates :name, :title
20
- globalize_accessors
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.2
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-13 00:00:00.000000000 Z
15
+ date: 2013-12-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: globalize