globalize-accessors 0.1.4 → 0.1.5

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: e6b68096730b07010773411f39a6765871049ac8
4
- data.tar.gz: ffe954c351fff999d909f3dd7b06f6cbb316c7b8
3
+ metadata.gz: ce6fd7599f86b6c3962521da63aba9d568360b3a
4
+ data.tar.gz: 27afe99b06330d8ef59bd09dfdee4b21571bac25
5
5
  SHA512:
6
- metadata.gz: 9bb53008d46631cf26b48442bac3f913c41e0814f9f3659da7bf3aaffa761fb7be2d1eca0069ff27786a3f04c6c42b467210cd99cd1b1d10df22d78b8c967b3f
7
- data.tar.gz: 86f3612c8aec29e123743e3db869fc243f7918074212a7d31d3f8a4cdf9951c8e00fb68497480561b6ec1886cc1b4698676c84558672af0acddd989bcb62b5b2
6
+ metadata.gz: 81581d05228b6664c5e4e81e32ec1b3b249ab8bc222bcbf2cef6d795ee97e056802a26a49504de10415dc047f559691bec7e1e1a127ec20b59cf8b5fb9019c41
7
+ data.tar.gz: 203866ebfd2e76a4753a679f0d5ed6bc339a80cf8d7edcc08c835ceee01e7f53f28bcb9789a7f70da0bcef61ff4c75a9d2ab111519a2333eea6bc4d9acde549f
@@ -11,6 +11,12 @@ module Globalize::Accessors
11
11
  each_attribute_and_locale(options) do |attr_name, locale|
12
12
  define_accessors(attr_name, locale)
13
13
  end
14
+
15
+ include InstanceMethods
16
+ end
17
+
18
+ def localized_attr_name_for(attr_name, locale)
19
+ "#{attr_name}_#{locale.to_s.underscore}"
14
20
  end
15
21
 
16
22
  private
@@ -21,13 +27,13 @@ module Globalize::Accessors
21
27
  end
22
28
 
23
29
  def define_getter(attr_name, locale)
24
- define_method :"#{attr_name}_#{locale.to_s.underscore}" do
30
+ define_method localized_attr_name_for(attr_name, locale) do
25
31
  globalize.stash.contains?(locale, attr_name) ? globalize.send(:fetch_stash, locale, attr_name) : globalize.send(:fetch_attribute, locale, attr_name)
26
32
  end
27
33
  end
28
34
 
29
35
  def define_setter(attr_name, locale)
30
- localized_attr_name = "#{attr_name}_#{locale.to_s.underscore}"
36
+ localized_attr_name = localized_attr_name_for(attr_name, locale)
31
37
 
32
38
  define_method :"#{localized_attr_name}=" do |value|
33
39
  write_attribute(attr_name, value, :locale => locale)
@@ -47,6 +53,11 @@ module Globalize::Accessors
47
53
  end
48
54
  end
49
55
 
56
+ module InstanceMethods
57
+ def localized_attr_name_for(attr_name, locale)
58
+ self.class.localized_attr_name_for(attr_name, locale)
59
+ end
60
+ end
50
61
  end
51
62
 
52
63
  ActiveRecord::Base.extend Globalize::Accessors
@@ -1,5 +1,5 @@
1
1
  module Globalize
2
2
  module Accessors
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
@@ -36,10 +36,22 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
36
36
  globalize_accessors :locales => [:"pt-BR", :"en-AU"], :attributes => [:name]
37
37
  end
38
38
 
39
+ class UnitWithoutAccessors < ActiveRecord::Base
40
+ self.table_name = :units
41
+ end
42
+
39
43
  setup do
40
44
  assert_equal :en, I18n.locale
41
45
  end
42
46
 
47
+ test "return localized attribute names" do
48
+ u = UnitWithDashedLocales.new
49
+
50
+ assert_equal "name_en", u.localized_attr_name_for(:name, :en)
51
+ assert_equal "name_pt_br", u.localized_attr_name_for(:name, :"pt-BR")
52
+ assert_equal "name_zh_cn", u.class.localized_attr_name_for(:name, :"zh-CN")
53
+ end
54
+
43
55
  test "read and write on new object" do
44
56
  u = Unit.new(:name_en => "Name en", :title_pl => "Title pl")
45
57
 
@@ -196,4 +208,8 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
196
208
  assert_raise(NoMethodError) { Unit.new.globalize_attribute_names = [:name] }
197
209
  assert_raise(NoMethodError) { Unit.new.globalize_locales = [:en, :de] }
198
210
  end
211
+
212
+ test "instance without accessors" do
213
+ refute UnitWithoutAccessors.new.respond_to?(:localized_attr_name_for)
214
+ end
199
215
  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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Stachewicz
@@ -12,76 +12,76 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-07-29 00:00:00.000000000 Z
15
+ date: 2014-08-16 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: globalize
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - '>='
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: '3'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - '>='
28
+ - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  version: '3'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: bundler
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - '>='
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
37
  version: 1.3.5
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - '>='
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: 1.3.5
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: rake
47
47
  requirement: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - ~>
49
+ - - "~>"
50
50
  - !ruby/object:Gem::Version
51
51
  version: 0.9.2
52
52
  type: :development
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - ~>
56
+ - - "~>"
57
57
  - !ruby/object:Gem::Version
58
58
  version: 0.9.2
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: sqlite3
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - '>='
63
+ - - ">="
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - '>='
70
+ - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: minitest
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ~>
77
+ - - "~>"
78
78
  - !ruby/object:Gem::Version
79
79
  version: '4.2'
80
80
  type: :development
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ~>
84
+ - - "~>"
85
85
  - !ruby/object:Gem::Version
86
86
  version: '4.2'
87
87
  description: Define methods for accessing translated attributes
@@ -95,8 +95,8 @@ executables: []
95
95
  extensions: []
96
96
  extra_rdoc_files: []
97
97
  files:
98
- - .gitignore
99
- - .travis.yml
98
+ - ".gitignore"
99
+ - ".travis.yml"
100
100
  - Gemfile
101
101
  - MIT-LICENSE
102
102
  - Rakefile
@@ -118,19 +118,18 @@ require_paths:
118
118
  - lib
119
119
  required_ruby_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - '>='
126
+ - - ">="
127
127
  - !ruby/object:Gem::Version
128
128
  version: '1.3'
129
129
  requirements: []
130
130
  rubyforge_project: globalize-accessors
131
- rubygems_version: 2.2.0
131
+ rubygems_version: 2.2.2
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Define methods for accessing translated attributes
135
135
  test_files: []
136
- has_rdoc: