locale 2.0.9 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c70c3a79e17ab4cc5af32c055728d0a2d5af6a7a
4
+ data.tar.gz: d8ca3c3e5f44decdbc49f76d4c48e3157bcd1f1a
5
+ SHA512:
6
+ metadata.gz: b17b7898fcd4f80c350ae9441eba2b48dcfbb2f0d44bb319eeb27146394370e66d8b2dba4a616838301a6c6ca0d8313ffe7ec1c798b4e4d45c28df2b8138f31c
7
+ data.tar.gz: 634726bcd248a4babdc6748d030ee6c0a18af5564c79c2447ce185f549b8d38697edf1e45200033cc417a8114344b4f6dfc5277a4d58cfbeaf34f74e912e1dee
@@ -67,9 +67,6 @@ LGPL(Lesser General Public License: http://www.gnu.org/licenses/lgpl-3.0.txt).
67
67
  * langtag-0.1.0
68
68
  * by Martin Dürst <http://rubyforge.org/projects/langtag/>
69
69
 
70
- * memoizable.rb
71
- * from ActiveSupport-2.2.0 <http://rubyforge.org/projects/activesupport/>
72
-
73
70
  * gettext gem
74
71
  * by The ruby-gettext project <https://ruby-gettext.github.com/>
75
72
 
@@ -1,5 +1,18 @@
1
1
  # News
2
2
 
3
+ ## <a id="2-1-0">2.1.0</a>: 2013-12-15
4
+
5
+ ### Fixes
6
+
7
+ * Fixed a bug that memoization key hash collision on armv7hl.
8
+ Memoization feature is removed for this fix. If you get
9
+ performance issue. Please report it. We will solve the issue.
10
+ [GitHub#3] [Reported by mtasaka]
11
+
12
+ ### Thanks
13
+
14
+ * mtasaka
15
+
3
16
  ## <a id="2-0-9">2.0.9</a>: 2013-09-20
4
17
 
5
18
  Locale handling fix release.
@@ -12,7 +12,6 @@
12
12
  $Id: locale.rb 27 2008-12-03 15:06:50Z mutoh $
13
13
  =end
14
14
 
15
- require 'locale/util/memoizable'
16
15
  require 'locale/tag'
17
16
  require 'locale/taglist'
18
17
  require 'locale/driver'
@@ -25,8 +24,6 @@ module Locale
25
24
  @@default_tag = nil
26
25
  @@driver_name = nil
27
26
 
28
- include Locale::Util::Memoizable
29
-
30
27
  module_function
31
28
  def require_driver(name) #:nodoc:
32
29
  require "locale/driver/#{name}"
@@ -213,21 +210,19 @@ module Locale
213
210
  # The type of language tag. :common, :rfc, :cldr, :posix and
214
211
  # :simple are available. Default value is :common
215
212
  def candidates(options = {})
216
- opts = {:supported_language_tags => nil, :current => current,
217
- :type => :common}.merge(options)
218
-
219
- if Thread.current[:candidates_caches]
220
- cache = Thread.current[:candidates_caches][opts.hash]
221
- return cache if cache
222
- else
223
- Thread.current[:candidates_caches] = {}
224
- end
225
- Thread.current[:candidates_caches][opts.hash] =
213
+ opts = {
214
+ :supported_language_tags => nil,
215
+ :current => current,
216
+ :type => :common,
217
+ }.merge(options)
218
+
219
+ Thread.current[:candidates_caches] ||= {}
220
+ Thread.current[:candidates_caches][opts] ||=
226
221
  collect_candidates(opts[:type], opts[:current],
227
222
  opts[:supported_language_tags])
228
223
  end
229
224
 
230
- # collect tag candidates and memoize it.
225
+ # collect tag candidates.
231
226
  # The result is shared from all threads.
232
227
  def collect_candidates(type, tags, supported_tags) # :nodoc:
233
228
  candidate_tags = tags.collect{|v| v.send("to_#{type}").candidates}
@@ -265,7 +260,6 @@ module Locale
265
260
 
266
261
  Locale::TagList.new(tags)
267
262
  end
268
- memoize :collect_candidates
269
263
 
270
264
  # Gets the current charset.
271
265
  #
@@ -276,7 +270,6 @@ module Locale
276
270
  def charset
277
271
  driver_module.charset || "UTF-8"
278
272
  end
279
- memoize :charset
280
273
 
281
274
  # Clear current locale.
282
275
  # * Returns: self
@@ -295,7 +288,6 @@ module Locale
295
288
  thread[:current_languages] = nil
296
289
  thread[:candidates_caches] = nil
297
290
  end
298
- memoize_clear
299
291
  self
300
292
  end
301
293
 
@@ -13,13 +13,11 @@ require 'locale/tag/common'
13
13
  require 'locale/tag/rfc'
14
14
  require 'locale/tag/cldr'
15
15
  require 'locale/tag/posix'
16
- require 'locale/util/memoizable'
17
16
 
18
17
  module Locale
19
18
 
20
19
  # Language tag / locale identifiers.
21
20
  module Tag
22
- include Util::Memoizable
23
21
  module_function
24
22
  # Parse a language tag/locale name and return Locale::Tag
25
23
  # object.
@@ -33,7 +31,6 @@ module Locale
33
31
  end
34
32
  Locale::Tag::Irregular.new(tag)
35
33
  end
36
- memoize :parse
37
34
  end
38
35
  end
39
36
 
@@ -26,7 +26,6 @@ module Locale
26
26
  attr_reader :extensions
27
27
 
28
28
  class << self
29
- include Util::Memoizable
30
29
  # Parse the language tag and return the new Locale::Tag::CLDR.
31
30
  def parse(tag)
32
31
  if tag =~ /\APOSIX\Z/ # This is the special case of POSIX locale but match this regexp.
@@ -49,7 +48,6 @@ module Locale
49
48
  nil
50
49
  end
51
50
  end
52
- memoize_dup :parse
53
51
  end
54
52
 
55
53
  # Create Locale::Tag::Cldr.
@@ -63,7 +61,6 @@ module Locale
63
61
 
64
62
  # Sets the extensions as an Hash.
65
63
  def extensions=(val)
66
- clear
67
64
  @extensions = val
68
65
  end
69
66
 
@@ -33,7 +33,6 @@ module Locale
33
33
  attr_reader :script, :variants
34
34
 
35
35
  class << self
36
- include Util::Memoizable
37
36
  # Parse the language tag and return the new Locale::Tag::Common.
38
37
  def parse(tag)
39
38
  if tag =~ /\APOSIX\Z/ # This is the special case of POSIX locale but match this regexp.
@@ -49,7 +48,6 @@ module Locale
49
48
  nil
50
49
  end
51
50
  end
52
- memoize_dup :parse
53
51
  end
54
52
 
55
53
  # Create a Locale::Tag::Common.
@@ -61,7 +59,6 @@ module Locale
61
59
 
62
60
  # Set the script (with capitalize)
63
61
  def script=(val)
64
- clear
65
62
  @script = val
66
63
  @script = @script.capitalize if @script
67
64
  @script
@@ -69,7 +66,6 @@ module Locale
69
66
 
70
67
  # Set the variants as an Array.
71
68
  def variants=(val)
72
- clear
73
69
  @variants = val
74
70
  end
75
71
 
@@ -88,7 +84,6 @@ module Locale
88
84
  self.class.new(language, nil, nil, variants), #ja-FOO
89
85
  self.class.new(language)] #ja
90
86
  end
91
- memoize_dup :candidates
92
87
 
93
88
  private
94
89
  def convert_to(klass) #:nodoc:
@@ -27,14 +27,12 @@ module Locale
27
27
  def candidates
28
28
  [Irregular.new(tag)]
29
29
  end
30
- memoize :candidates
31
-
30
+
32
31
  # Conver to the klass(the class of Language::Tag)
33
32
  private
34
33
  def convert_to(klass)
35
34
  klass.new(tag)
36
35
  end
37
- memoize :convert_to
38
36
  end
39
37
  end
40
38
  end
@@ -56,13 +56,11 @@ module Locale
56
56
 
57
57
  # Set the charset.
58
58
  def charset=(val)
59
- clear
60
59
  @charset = val
61
60
  end
62
61
 
63
62
  # Set the modifier as a String
64
63
  def modifier=(val)
65
- clear
66
64
  @modifier = val
67
65
  end
68
66
 
@@ -27,7 +27,6 @@ module Locale
27
27
  attr_reader :extensions, :privateuse
28
28
 
29
29
  class << self
30
- include Util::Memoizable
31
30
  # Parse the language tag and return the new Locale::Tag::Rfc.
32
31
  def parse(tag)
33
32
  if tag =~ /\APOSIX\Z/ # This is the special case of POSIX locale but match this regexp.
@@ -55,7 +54,6 @@ module Locale
55
54
  nil
56
55
  end
57
56
  end
58
- memoize_dup :parse
59
57
  end
60
58
 
61
59
  def initialize(language, script = nil, region = nil, variants = [],
@@ -66,13 +64,11 @@ module Locale
66
64
 
67
65
  # Sets the extensions as an Array.
68
66
  def extensions=(val)
69
- clear
70
67
  @extensions = val
71
68
  end
72
69
 
73
70
  # Sets the privateuse as a String
74
71
  def privateuse=(val)
75
- clear
76
72
  @privateuse = val
77
73
  end
78
74
 
@@ -7,8 +7,6 @@
7
7
  license terms as Ruby.
8
8
  =end
9
9
 
10
- require 'locale/util/memoizable'
11
-
12
10
  module Locale
13
11
  module Tag
14
12
  # Abstract language tag class.
@@ -20,8 +18,6 @@ module Locale
20
18
  # * ja-JP
21
19
  # * ja-392
22
20
  class Simple
23
- include Util::Memoizable
24
-
25
21
  ALPHA = '[a-z]'
26
22
  DIGIT = '[0-9]'
27
23
  ALPHANUM = "[a-zA-Z0-9]"
@@ -31,8 +27,6 @@ module Locale
31
27
 
32
28
  TAG_RE = /\A#{LANGUAGE}(?:[_-]#{REGION})?\Z/i
33
29
 
34
- include Util::Memoizable
35
-
36
30
  attr_reader :language, :region
37
31
 
38
32
  # tag is set when .parse method is called.
@@ -52,12 +46,10 @@ module Locale
52
46
  def to_#{name}
53
47
  convert_to(#{name.to_s.capitalize})
54
48
  end
55
- memoize_dup :to_#{name}
56
49
  EOS
57
50
  end
58
51
 
59
52
  class << self
60
- include Util::Memoizable
61
53
  # Parse the language tag and return the new Locale::Tag::Simple.
62
54
  def parse(tag)
63
55
  if tag =~ TAG_RE
@@ -68,7 +60,6 @@ module Locale
68
60
  nil
69
61
  end
70
62
  end
71
- memoize_dup :parse
72
63
  end
73
64
 
74
65
  # Create a Locale::Tag::Simple
@@ -85,7 +76,6 @@ module Locale
85
76
  def to_s
86
77
  to_string
87
78
  end
88
- memoize :to_s
89
79
 
90
80
  def to_str #:nodoc:
91
81
  to_s
@@ -102,24 +92,20 @@ module Locale
102
92
  def eql?(other) #:nodoc:
103
93
  self.==(other)
104
94
  end
105
- memoize :eql?
106
95
 
107
96
  def hash #:nodoc:
108
97
  "#{self.class}:#{to_s}".hash
109
98
  end
110
- memoize :hash
111
99
 
112
100
  def inspect #:nodoc:
113
101
  %Q[#<#{self.class}: #{to_s}>]
114
102
  end
115
- memoize :inspect
116
103
 
117
104
  # For backward compatibility.
118
105
  def country; region end
119
106
 
120
107
  # Set the language (with downcase)
121
108
  def language=(val)
122
- clear
123
109
  @language = val
124
110
  @language = @language.downcase if @language
125
111
  @language
@@ -127,7 +113,6 @@ module Locale
127
113
 
128
114
  # Set the region (with upcase)
129
115
  def region=(val)
130
- clear
131
116
  @region = val
132
117
  @region = @region.upcase if @region
133
118
  @region
@@ -138,7 +123,6 @@ module Locale
138
123
  def candidates
139
124
  [self.class.new(language, region), self.class.new(language)]
140
125
  end
141
- memoize_dup :candidates
142
126
 
143
127
  # Convert to the klass(the class of Language::Tag)
144
128
  private
@@ -9,8 +9,6 @@
9
9
  $Id: taglist.rb 27 2008-12-03 15:06:50Z mutoh $
10
10
  =end
11
11
 
12
- require 'locale/util/memoizable'
13
-
14
12
  module Locale
15
13
  # This provides the subclass of Array which behaves like
16
14
  # the first(top priority) Locale::Tag object.
@@ -26,8 +24,6 @@ module Locale
26
24
  # of this function.
27
25
  #
28
26
  class TagList < Array
29
- include Util::Memoizable
30
-
31
27
  # Returns the top priority language. (simple)
32
28
  def language
33
29
  self[0].language
@@ -54,31 +50,26 @@ module Locale
54
50
  top_priority_charset ||= ::Locale.driver_module.charset
55
51
  top_priority_charset
56
52
  end
57
- memoize :charset
58
53
 
59
54
  # Returns the top priority modifier. (posix)
60
55
  def modifier
61
56
  (self[0].respond_to? :modifier) ? self[0].modifier : nil
62
57
  end
63
- memoize :modifier
64
58
 
65
59
  # Returns the top priority variants.(common, rfc, cldr)
66
60
  def variants
67
61
  (self[0].respond_to? :variants) ? self[0].variants : nil
68
62
  end
69
- memoize :variants
70
63
 
71
64
  # Returns the top priority extensions.(common, rfc, cldr)
72
65
  def extensions
73
66
  (self[0].respond_to? :extensions) ? self[0].extensions : nil
74
67
  end
75
- memoize :extensions
76
68
 
77
69
  # Returns the top priority privateuse(rfc)
78
70
  def privateuse
79
71
  (self[0].respond_to? :privateuse) ? self[0].privateuse : nil
80
72
  end
81
- memoize :privateuse
82
73
 
83
74
  def to_str
84
75
  self[0].to_str
@@ -2,11 +2,12 @@
2
2
  version - version information of Ruby-Locale
3
3
 
4
4
  Copyright (C) 2008 Masao Mutoh
5
+ Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
5
6
 
6
7
  You may redistribute it and/or modify it under the same
7
8
  license terms as Ruby.
8
9
  =end
9
10
  module Locale
10
- VERSION = "2.0.9"
11
+ VERSION = "2.1.0"
11
12
  end
12
13
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locale
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
5
- prerelease:
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kouhei Sutou
@@ -10,124 +9,108 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-09-20 00:00:00.000000000 Z
12
+ date: 2013-12-15 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rake
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: bundler
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: yard
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: redcarpet
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: test-unit
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: test-unit-notify
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - '>='
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - '>='
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: test-unit-rr
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ! '>='
102
+ - - '>='
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ! '>='
109
+ - - '>='
125
110
  - !ruby/object:Gem::Version
126
111
  version: '0'
127
- description: ! 'Ruby-Locale is the pure ruby library which provides basic APIs for
128
- localization.
129
-
130
- '
112
+ description: |
113
+ Ruby-Locale is the pure ruby library which provides basic APIs for localization.
131
114
  email:
132
115
  - kou@clear-code.com
133
116
  - mutomasa at gmail.com
@@ -156,7 +139,6 @@ files:
156
139
  - lib/locale/middleware.rb
157
140
  - lib/locale/data/languages.tab.gz
158
141
  - lib/locale/data/regions.tab.gz
159
- - lib/locale/util/memoizable.rb
160
142
  - lib/locale/taglist.rb
161
143
  - lib/locale.rb
162
144
  - samples/cgi/README
@@ -184,7 +166,6 @@ files:
184
166
  - test/test_locale.rb
185
167
  - test/test_thread.rb
186
168
  - test/test_info.rb
187
- - test/test_memoizable.rb
188
169
  - test/test_driver_jruby.rb
189
170
  - test/test_driver_win32.rb
190
171
  - test/test_detect_general.rb
@@ -192,27 +173,26 @@ homepage: https://github.com/ruby-gettext/locale
192
173
  licenses:
193
174
  - Ruby
194
175
  - LGPLv3+
176
+ metadata: {}
195
177
  post_install_message:
196
178
  rdoc_options: []
197
179
  require_paths:
198
180
  - lib
199
181
  required_ruby_version: !ruby/object:Gem::Requirement
200
- none: false
201
182
  requirements:
202
- - - ! '>='
183
+ - - '>='
203
184
  - !ruby/object:Gem::Version
204
185
  version: '0'
205
186
  required_rubygems_version: !ruby/object:Gem::Requirement
206
- none: false
207
187
  requirements:
208
- - - ! '>='
188
+ - - '>='
209
189
  - !ruby/object:Gem::Version
210
190
  version: '0'
211
191
  requirements: []
212
192
  rubyforge_project:
213
- rubygems_version: 1.8.23
193
+ rubygems_version: 2.0.14
214
194
  signing_key:
215
- specification_version: 3
195
+ specification_version: 4
216
196
  summary: Ruby-Locale is the pure ruby library which provides basic APIs for localization.
217
197
  test_files:
218
198
  - test/test_tag.rb
@@ -221,7 +201,6 @@ test_files:
221
201
  - test/test_locale.rb
222
202
  - test/test_thread.rb
223
203
  - test/test_info.rb
224
- - test/test_memoizable.rb
225
204
  - test/test_driver_jruby.rb
226
205
  - test/test_driver_win32.rb
227
206
  - test/test_detect_general.rb
@@ -1,108 +0,0 @@
1
- # Refer from activesupport-2.2.0.
2
- #
3
- # * Remove the dependecies to activesupport.
4
- # * change the key to hash value of args.
5
- # * Not Thread safe
6
- # * Add the clear method.
7
- module Locale
8
- module Util
9
- module Memoizable
10
- MEMOIZED_IVAR = Proc.new do |symbol|
11
- "#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
12
- end
13
-
14
- def self.included(base)
15
- mod = self
16
- base.class_eval do
17
- extend mod
18
- end
19
- end
20
-
21
- alias :freeze_without_memoizable :freeze #:nodoc:
22
- def freeze #:nodoc:
23
- unless frozen?
24
- @_memoized_ivars = {}
25
- freeze_without_memoizable
26
- end
27
- end
28
-
29
- # Clear memoized values. Deprecated.
30
- def clear # :nodoc:
31
- @_memoized_ivars = {}
32
- end
33
-
34
- # Clear memoized values.
35
- def memoize_clear
36
- @_memoized_ivars = {}
37
- end
38
-
39
- # Cache the result of the methods.
40
- #
41
- # include Memoizable
42
- # def foo
43
- # ......
44
- # end
45
- # def bar(a, b)
46
- # ......
47
- # end
48
- # memoize :foo, :bar(a, b)
49
- #
50
- # To clear cache, #clear_foo, #clear_bar is also defined.
51
- #
52
- # (NOTE)
53
- # * Consider to use this with huge objects to avoid memory leaks.
54
- # * Can't use this with super.<method> because of infinity loop.
55
- def memoize(*symbols)
56
- memoize_impl(false, *symbols)
57
- end
58
-
59
- # memoize with dup. A copy object is returned.
60
- def memoize_dup(*symbols)
61
- memoize_impl(true, *symbols)
62
- end
63
-
64
- def memoize_impl(is_dup, *symbols) #:nodoc:
65
- symbols.each do |symbol|
66
- original_method = "_unmemoized_#{symbol}"
67
- memoized_ivar = MEMOIZED_IVAR.call(symbol)
68
- dup_meth = is_dup ? "_dup" : ""
69
-
70
- class_eval <<-EOS, __FILE__, __LINE__
71
- alias #{original_method} #{symbol}
72
- def #{symbol}(*args)
73
- _memoize#{dup_meth}(:#{memoized_ivar}, args.hash) do
74
- #{original_method}(*args)
75
- end
76
- end
77
- EOS
78
- end
79
- end
80
-
81
- def _memoize(ivar, key) #:nodoc:
82
- @_memoized_ivars ||= {}
83
- @_memoized_ivars[ivar] ||= {}
84
-
85
- ret = @_memoized_ivars[ivar][key]
86
- unless ret
87
- ret = yield
88
- ret.freeze
89
- @_memoized_ivars[ivar][key] = ret
90
- end
91
- ret
92
- end
93
-
94
- def _memoize_dup(ivar, key) #:nodoc:
95
- ret = _memoize(ivar, key) do; yield; end
96
- if ret
97
- if ret.kind_of? Array
98
- ret.map{|v| v.dup}.dup
99
- else
100
- ret.dup
101
- end
102
- else
103
- nil
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,133 +0,0 @@
1
- require 'locale/util/memoizable'
2
- require 'test/unit'
3
-
4
- class A
5
- include Locale::Util::Memoizable
6
- def initialize
7
- @count = 0
8
- @a = ""
9
- end
10
- def test1(a)
11
- @a += String(a)
12
- @count += 1
13
- end
14
- memoize :test1
15
- attr_reader :a
16
- end
17
-
18
- class B < A
19
- end
20
-
21
- class C < A
22
- def test1(a)
23
- @a = String(a) + @a
24
- @count += 1
25
- end
26
- memoize :test1
27
- end
28
-
29
- class D
30
- class << self
31
- include Locale::Util::Memoizable
32
- def init
33
- @@count = 0
34
- @@a = "a"
35
- end
36
- def test1(a)
37
- @@a = @@a + "b" * a
38
- @@count += 1
39
- end
40
- memoize :test1
41
- def a
42
- @@a
43
- end
44
- end
45
- end
46
-
47
- class E
48
- include Locale::Util::Memoizable
49
- def test2
50
- "aa"
51
- end
52
- memoize :test2
53
-
54
- def test2_dup
55
- "bb"
56
- end
57
- memoize_dup :test2_dup
58
- end
59
-
60
- class TestMemoizable < Test::Unit::TestCase
61
- def test_simple
62
- t = A.new
63
- assert_equal 1, t.test1(1)
64
- assert_equal "1", t.a
65
- assert_equal 1, t.test1(1)
66
- assert_equal "1", t.a
67
- assert_equal 2, t.test1(2)
68
- assert_equal "12", t.a
69
- assert_equal 2, t.test1(2)
70
- assert_equal "12", t.a
71
- assert_equal 1, t.test1(1)
72
- assert_equal "12", t.a
73
- end
74
-
75
- def test_simple_inherited
76
- t = B.new
77
- assert_equal 1, t.test1(1)
78
- assert_equal "1", t.a
79
- assert_equal 1, t.test1(1)
80
- assert_equal "1", t.a
81
- assert_equal 2, t.test1(2)
82
- assert_equal "12", t.a
83
- assert_equal 2, t.test1(2)
84
- assert_equal "12", t.a
85
- assert_equal 1, t.test1(1)
86
- assert_equal "12", t.a
87
- end
88
-
89
- def test_override
90
- t = C.new
91
- assert_equal 1, t.test1(1)
92
- assert_equal "1", t.a
93
- assert_equal 1, t.test1(1)
94
- assert_equal "1", t.a
95
- assert_equal 2, t.test1(2)
96
- assert_equal "21", t.a
97
- assert_equal 2, t.test1(2)
98
- assert_equal "21", t.a
99
- assert_equal 1, t.test1(1)
100
- assert_equal "21", t.a
101
- end
102
-
103
- def test_class_method
104
- D.init
105
- assert_equal 1, D.test1(1)
106
- assert_equal "ab", D.a
107
- assert_equal 1, D.test1(1)
108
- assert_equal "ab", D.a
109
- assert_equal 2, D.test1(2)
110
- assert_equal "abbb", D.a
111
- assert_equal 2, D.test1(2)
112
- assert_equal "abbb", D.a
113
- assert_equal 1, D.test1(1)
114
- assert_equal "abbb", D.a
115
- end
116
-
117
- def test_freeze_or_dup
118
- t = E.new
119
- assert_equal "aa", t.test2
120
- # When modification attempted on frozen objects,
121
- # ruby 1.9 raises RuntimeError instead of TypeError.
122
- # http://redmine.ruby-lang.org/issues/show/409
123
- # http://redmine.ruby-lang.org/repositories/diff/ruby-19/error.c?rev=7294
124
- if RUBY_VERSION < '1.9.0'
125
- assert_raise(TypeError){ t.test2 << "a" }
126
- else
127
- assert_raise(RuntimeError){ t.test2 << "a" }
128
- end
129
- assert_equal "bb", t.test2_dup
130
- assert_equal "bbb", t.test2_dup << "b"
131
- assert_equal "bb", t.test2_dup
132
- end
133
- end