locale 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/ChangeLog +3 -0
  2. data/benchmark/benchmark.rb +34 -0
  3. data/benchmark/benchmark_2.0.1.txt +7 -0
  4. data/doc/classes/Locale.html +1244 -0
  5. data/doc/classes/Locale/Driver.html +374 -0
  6. data/doc/classes/Locale/Driver/CGI.html +536 -0
  7. data/doc/classes/Locale/Driver/Env.html +439 -0
  8. data/doc/classes/Locale/Driver/JRuby.html +389 -0
  9. data/doc/classes/Locale/Driver/Posix.html +430 -0
  10. data/doc/classes/Locale/Driver/Win32.html +398 -0
  11. data/doc/classes/Locale/Driver/Win32Table.html +355 -0
  12. data/doc/classes/Locale/Info.html +585 -0
  13. data/doc/classes/Locale/Info/Language.html +763 -0
  14. data/doc/classes/Locale/Info/Region.html +470 -0
  15. data/doc/classes/Locale/Tag.html +433 -0
  16. data/doc/classes/Locale/Tag/Cldr.html +523 -0
  17. data/doc/classes/Locale/Tag/Common.html +624 -0
  18. data/doc/classes/Locale/Tag/Irregular.html +423 -0
  19. data/doc/classes/Locale/Tag/Posix.html +612 -0
  20. data/doc/classes/Locale/Tag/Rfc.html +581 -0
  21. data/doc/classes/Locale/Tag/Simple.html +721 -0
  22. data/doc/classes/Locale/TagList.html +826 -0
  23. data/doc/classes/Locale/Util.html +506 -0
  24. data/doc/classes/Locale/Util/Memoizable.html +355 -0
  25. data/doc/created.rid +1 -0
  26. data/doc/files/ChangeLog.html +537 -0
  27. data/doc/files/README_rdoc.html +565 -0
  28. data/doc/files/lib/locale/driver/cgi_rb.html +341 -0
  29. data/doc/files/lib/locale/driver/env_rb.html +353 -0
  30. data/doc/files/lib/locale/driver/jruby_rb.html +353 -0
  31. data/doc/files/lib/locale/driver/posix_rb.html +341 -0
  32. data/doc/files/lib/locale/driver/win32_rb.html +348 -0
  33. data/doc/files/lib/locale/driver/win32_table_rb.html +341 -0
  34. data/doc/files/lib/locale/info/language_rb.html +352 -0
  35. data/doc/files/lib/locale/info/region_rb.html +352 -0
  36. data/doc/files/lib/locale/info_rb.html +353 -0
  37. data/doc/files/lib/locale/tag/cldr_rb.html +348 -0
  38. data/doc/files/lib/locale/tag/common_rb.html +348 -0
  39. data/doc/files/lib/locale/tag/irregular_rb.html +348 -0
  40. data/doc/files/lib/locale/tag/posix_rb.html +341 -0
  41. data/doc/files/lib/locale/tag/rfc_rb.html +348 -0
  42. data/doc/files/lib/locale/tag/simple_rb.html +348 -0
  43. data/doc/files/lib/locale/tag_rb.html +378 -0
  44. data/doc/files/lib/locale/taglist_rb.html +348 -0
  45. data/doc/files/lib/locale/util/memoizable_rb.html +359 -0
  46. data/doc/files/lib/locale/version_rb.html +341 -0
  47. data/doc/files/lib/locale_rb.html +363 -0
  48. data/doc/fr_class_index.html +22 -0
  49. data/doc/fr_file_index.html +23 -0
  50. data/doc/fr_method_index.html +99 -0
  51. data/doc/index.html +1 -0
  52. data/doc/rdoc-style.css +320 -0
  53. data/lib/locale/util/memoizable.rb.20090328 +96 -0
  54. data/lib/locale/util/memoizable.rb.old +91 -0
  55. data/lib/locale/version.rb +1 -1
  56. data/replace.rb +21 -0
  57. data/test.rb +28 -0
  58. data/test/test.rb +7 -0
  59. data/test/tmp.txt +20 -0
  60. data/test2.rb +14 -0
  61. data/test3.rb +12 -0
  62. metadata +75 -1
@@ -0,0 +1,96 @@
1
+ # Refer from activesupport-2.2.0.
2
+ # * Remove the dependecies to activesupport.
3
+ # * change the key to hash value of args.
4
+ # * Not Thread safe
5
+ # * Add the clear method.
6
+ module Locale
7
+ module Util
8
+ module Memoizable
9
+ MEMOIZED_IVAR = Proc.new do |symbol|
10
+ "#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
11
+ end
12
+
13
+ def self.included(base)
14
+ mod = self
15
+ base.class_eval do
16
+ extend mod
17
+ end
18
+ end
19
+
20
+ alias :freeze_without_memoizable :freeze #:nodoc:
21
+ def freeze #:nodoc:
22
+ unless frozen?
23
+ @_memoized_ivars = {}
24
+ freeze_without_memoizable
25
+ end
26
+ end
27
+
28
+ # Clear memoized values.
29
+ def clear
30
+ @_memoized_ivars = {}
31
+ end
32
+
33
+ # Cache the result of the methods.
34
+ #
35
+ # include Memoizable
36
+ # def foo
37
+ # ......
38
+ # end
39
+ # def bar(a, b)
40
+ # ......
41
+ # end
42
+ # memoize :foo, :bar(a, b)
43
+ #
44
+ # To clear cache, #clear_foo, #clear_bar is also defined.
45
+ #
46
+ # (NOTE) Consider to use this with huge objects to avoid memory leaks.
47
+ def memoize(*symbols)
48
+ memoize_impl(false, symbols)
49
+ end
50
+
51
+ # memoize with dup. A copy object is returned.
52
+ def memoize_dup(*symbols)
53
+ memoize_impl(true, symbols)
54
+ end
55
+
56
+ def memoize_impl(is_dup, *symbols) #:nodoc:
57
+ symbols.each do |symbol|
58
+ original_method = "_unmemoized_#{symbol}"
59
+ memoized_ivar = MEMOIZED_IVAR.call(symbol)
60
+
61
+ class_eval <<-EOS, __FILE__, __LINE__
62
+ alias #{original_method} #{symbol}
63
+ def #{symbol}(*args)
64
+ _memoize(#{is_dup}, :#{memoized_ivar}, args.hash) do
65
+ #{original_method}(*args)
66
+ end
67
+ end
68
+ EOS
69
+ end
70
+ end
71
+
72
+ def _memoize(is_dup, ivar, key) #:nodoc:
73
+ @_memoized_ivars ||= {}
74
+ @_memoized_ivars[ivar] ||= {}
75
+
76
+ ret = @_memoized_ivars[ivar][key]
77
+ unless ret
78
+ ret = yield
79
+ ret.freeze
80
+ @_memoized_ivars[ivar][key] = ret
81
+ end
82
+
83
+ return ret unless is_dup
84
+ if ret
85
+ if ret.kind_of? Array
86
+ ret.map{|v| v.dup}.dup
87
+ else
88
+ ret.dup
89
+ end
90
+ else
91
+ nil
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,91 @@
1
+ # Refer from activesupport-2.2.0.
2
+ # * Remove the dependecies to activesupport.
3
+ # * change the key to hash value of args.
4
+ # * Not Thread safe
5
+ # * Add the clear method.
6
+ module Locale
7
+ module Util
8
+ module Memoizable
9
+ MEMOIZED_IVAR = Proc.new do |klass, symbol|
10
+ "#{klass.name.gsub(/::/, "_")}_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
11
+ end
12
+
13
+ def self.included(base)
14
+ mod = self
15
+ base.class_eval do
16
+ extend mod
17
+ end
18
+ end
19
+
20
+ alias :freeze_without_memoizable :freeze #:nodoc:
21
+ def freeze #:nodoc:
22
+ unless frozen?
23
+ @_memoized_ivars = {}
24
+ freeze_without_memoizable
25
+ end
26
+ end
27
+
28
+ # Clear memoized values.
29
+ def clear
30
+ @_memoized_ivars = {}
31
+ end
32
+
33
+ # Cache the result of the methods.
34
+ #
35
+ # include Memoizable
36
+ # def foo
37
+ # ......
38
+ # end
39
+ # def bar(a, b)
40
+ # ......
41
+ # end
42
+ # memoize :foo, :bar(a, b)
43
+ #
44
+ # To clear cache, #clear_foo, #clear_bar is also defined.
45
+ #
46
+ # (NOTE) Consider to use this with huge objects to avoid memory leaks.
47
+ def memoize(*symbols)
48
+ memoize_impl(false, symbols)
49
+ end
50
+
51
+ # memoize with dup. A copy object is returned.
52
+ def memoize_dup(*symbols)
53
+ memoize_impl(true, symbols)
54
+ end
55
+
56
+ def memoize_impl(is_dup, *symbols) #:nodoc:
57
+ symbols.each do |symbol|
58
+ original_method = "_unmemoized_#{symbol}"
59
+ memoized_ivar = MEMOIZED_IVAR.call(self, symbol)
60
+
61
+ class_eval <<-EOS, __FILE__, __LINE__
62
+ alias #{original_method} #{symbol}
63
+ def #{symbol}(*args)
64
+ @_memoized_ivars ||= {}
65
+ @_memoized_ivars[:#{memoized_ivar}] ||= {}
66
+
67
+ key = args.hash
68
+
69
+ ret = @_memoized_ivars[:#{memoized_ivar}][key]
70
+ print String(key) + "#{original_method}, #{memoized_ivar}" + ret.to_s + "\n"
71
+ if ret
72
+ p 1
73
+ ret
74
+ else
75
+ p @_memoized_ivars
76
+ p 222222222
77
+ p "#{original_method}(*args).freeze"
78
+ if "Locale_Tag_Common_to_s" == "#{memoized_ivar}"
79
+ p @_memoized_ivars[:#{memoized_ivar}][key] = super.#{original_method}(*args).freeze
80
+ else
81
+ p 11111111111
82
+ @_memoized_ivars[:#{memoized_ivar}][key] = #{original_method}(*args).freeze
83
+ end
84
+ end
85
+ end
86
+ EOS
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -7,6 +7,6 @@
7
7
  license terms as Ruby.
8
8
  =end
9
9
  module Locale
10
- VERSION = "2.0.2"
10
+ VERSION = "2.0.3"
11
11
  end
12
12
 
data/replace.rb ADDED
@@ -0,0 +1,21 @@
1
+ Dir.glob("**/*") do |v|
2
+ lines = []
3
+ changed = false
4
+ next if File.directory? v
5
+ IO.foreach(v) {|line|
6
+ if line =~ /mutoh(at|@)highway.ne.jp/
7
+ lines << line.gsub(/mutoh( at |@)highway.ne.jp/, "mutomasa at gmail.com")
8
+ changed = true
9
+ else
10
+ lines << line
11
+ end
12
+ }
13
+ if changed
14
+ out = open(v, "w")
15
+ lines.each {|l|
16
+ out.write l
17
+ }
18
+ out.close
19
+ end
20
+ end
21
+
data/test.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'locale/util/memoizable'
2
+
3
+ class Test
4
+ include Locale::Util::Memoizable
5
+ def set_test(a)
6
+ p "set_test"
7
+ @a = a
8
+ end
9
+ memoize :set_test
10
+ def test
11
+ @a
12
+ end
13
+ end
14
+
15
+ class Test2 < Test
16
+ def set_test(a)
17
+ p "set_test2"
18
+ @a = a
19
+ end
20
+ memoize :set_test
21
+ end
22
+
23
+
24
+ a = Test.new
25
+ a.set_test(1)
26
+ a.set_test(1)
27
+ a.set_test(1)
28
+ p a.test
data/test/test.rb ADDED
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+
3
+ require 'locale'
4
+
5
+ p a = Locale::Tag::Rfc.parse("ja-JP-MOBILE")
6
+
7
+ p a.to_posix
data/test/tmp.txt ADDED
@@ -0,0 +1,20 @@
1
+ -581759920_unmemoized_parse, _parse
2
+ {:_parse=>{}}
3
+ 222222222
4
+ "_unmemoized_parse(*args).freeze"
5
+ 11111111111
6
+ 0_unmemoized_inspect, Locale_Tag_Simple_inspect
7
+ {:Locale_Tag_Simple_inspect=>{}}
8
+ 222222222
9
+ "_unmemoized_inspect(*args).freeze"
10
+ 11111111111
11
+ 0_unmemoized_to_s, Locale_Tag_Rfc_to_s
12
+ {:Locale_Tag_Simple_inspect=>{}, :Locale_Tag_Rfc_to_s=>{}}
13
+ 222222222
14
+ "_unmemoized_to_s(*args).freeze"
15
+ 11111111111
16
+ "rfc.to_s, 1"
17
+ 0_unmemoized_to_s, Locale_Tag_Common_to_s
18
+ {:Locale_Tag_Common_to_s=>{}, :Locale_Tag_Simple_inspect=>{}, :Locale_Tag_Rfc_to_s=>{}}
19
+ 222222222
20
+ "_unmemoized_to_s(*args).freeze"
data/test2.rb ADDED
@@ -0,0 +1,14 @@
1
+ class Test
2
+ def test(a)
3
+ @a = a
4
+ end
5
+ alias :test_new :test
6
+ end
7
+
8
+ class Test2 < Test
9
+ def test(a)
10
+ @a = a + 1
11
+ end
12
+ end
13
+
14
+ p Test2.new.test_new(1)
data/test3.rb ADDED
@@ -0,0 +1,12 @@
1
+ $:.insert(0, "lib")
2
+ #require 'benchmark'
3
+ require 'locale'
4
+
5
+ #Benchmark.bm(18){|x|
6
+ # x.report("bindtextdomain"){ 100000.times{|i|
7
+ (0...100000).each {
8
+ Locale.candidates
9
+ # }
10
+ # }
11
+ }
12
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locale
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masao Mutoh
@@ -22,7 +22,72 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
+ - test.rb
26
+ - replace.rb
25
27
  - ChangeLog
28
+ - doc
29
+ - doc/index.html
30
+ - doc/fr_method_index.html
31
+ - doc/created.rid
32
+ - doc/fr_class_index.html
33
+ - doc/classes
34
+ - doc/classes/Locale
35
+ - doc/classes/Locale/Util.html
36
+ - doc/classes/Locale/Tag
37
+ - doc/classes/Locale/Tag/Irregular.html
38
+ - doc/classes/Locale/Tag/Simple.html
39
+ - doc/classes/Locale/Tag/Rfc.html
40
+ - doc/classes/Locale/Tag/Cldr.html
41
+ - doc/classes/Locale/Tag/Posix.html
42
+ - doc/classes/Locale/Tag/Common.html
43
+ - doc/classes/Locale/Info.html
44
+ - doc/classes/Locale/Tag.html
45
+ - doc/classes/Locale/Info
46
+ - doc/classes/Locale/Info/Region.html
47
+ - doc/classes/Locale/Info/Language.html
48
+ - doc/classes/Locale/TagList.html
49
+ - doc/classes/Locale/Util
50
+ - doc/classes/Locale/Util/Memoizable.html
51
+ - doc/classes/Locale/Driver.html
52
+ - doc/classes/Locale/Driver
53
+ - doc/classes/Locale/Driver/Win32.html
54
+ - doc/classes/Locale/Driver/Win32Table.html
55
+ - doc/classes/Locale/Driver/Env.html
56
+ - doc/classes/Locale/Driver/Posix.html
57
+ - doc/classes/Locale/Driver/CGI.html
58
+ - doc/classes/Locale/Driver/JRuby.html
59
+ - doc/classes/Locale.html
60
+ - doc/files
61
+ - doc/files/ChangeLog.html
62
+ - doc/files/lib
63
+ - doc/files/lib/locale_rb.html
64
+ - doc/files/lib/locale
65
+ - doc/files/lib/locale/driver
66
+ - doc/files/lib/locale/driver/win32_rb.html
67
+ - doc/files/lib/locale/driver/win32_table_rb.html
68
+ - doc/files/lib/locale/driver/posix_rb.html
69
+ - doc/files/lib/locale/driver/cgi_rb.html
70
+ - doc/files/lib/locale/driver/jruby_rb.html
71
+ - doc/files/lib/locale/driver/env_rb.html
72
+ - doc/files/lib/locale/version_rb.html
73
+ - doc/files/lib/locale/tag_rb.html
74
+ - doc/files/lib/locale/tag
75
+ - doc/files/lib/locale/tag/simple_rb.html
76
+ - doc/files/lib/locale/tag/rfc_rb.html
77
+ - doc/files/lib/locale/tag/posix_rb.html
78
+ - doc/files/lib/locale/tag/irregular_rb.html
79
+ - doc/files/lib/locale/tag/cldr_rb.html
80
+ - doc/files/lib/locale/tag/common_rb.html
81
+ - doc/files/lib/locale/info
82
+ - doc/files/lib/locale/info/language_rb.html
83
+ - doc/files/lib/locale/info/region_rb.html
84
+ - doc/files/lib/locale/taglist_rb.html
85
+ - doc/files/lib/locale/info_rb.html
86
+ - doc/files/lib/locale/util
87
+ - doc/files/lib/locale/util/memoizable_rb.html
88
+ - doc/files/README_rdoc.html
89
+ - doc/rdoc-style.css
90
+ - doc/fr_file_index.html
26
91
  - samples
27
92
  - samples/sample_info.rb
28
93
  - samples/rack
@@ -37,6 +102,9 @@ files:
37
102
  - samples/cgi/http.rb
38
103
  - samples/cgi/README
39
104
  - setup.rb
105
+ - benchmark
106
+ - benchmark/benchmark_2.0.1.txt
107
+ - benchmark/benchmark.rb
40
108
  - COPYING
41
109
  - lib
42
110
  - lib/locale
@@ -62,20 +130,26 @@ files:
62
130
  - lib/locale/info/region.rb
63
131
  - lib/locale/taglist.rb
64
132
  - lib/locale/util
133
+ - lib/locale/util/memoizable.rb.20090328
134
+ - lib/locale/util/memoizable.rb.old
65
135
  - lib/locale/util/memoizable.rb
66
136
  - lib/locale/data
67
137
  - lib/locale/data/regions.tab.gz
68
138
  - lib/locale/data/languages.tab.gz
69
139
  - lib/locale.rb
70
140
  - README.rdoc
141
+ - test3.rb
71
142
  - test
143
+ - test/test.rb
72
144
  - test/test_detect_general.rb
73
145
  - test/test_info.rb
74
146
  - test/test_memoizable.rb
147
+ - test/tmp.txt
75
148
  - test/test_thread.rb
76
149
  - test/test_taglist.rb
77
150
  - test/test_tag.rb
78
151
  - test/test_detect_cgi.rb
152
+ - test2.rb
79
153
  - Rakefile
80
154
  has_rdoc: true
81
155
  homepage: http://locale.rubyforge.org/