ruby-ext 0.2.13 → 0.2.15

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.
data/.git/COMMIT_EDITMSG CHANGED
@@ -1 +1 @@
1
- upd
1
+ upd theme
data/.git/index CHANGED
Binary file
data/.git/logs/HEAD CHANGED
@@ -22,3 +22,5 @@ a691900cb5b7378b173ce55a29de35c18b26cd6e 5aacd2a96731620b7d13e27058b419f4dd84c81
22
22
  5aacd2a96731620b7d13e27058b419f4dd84c814 b71b49e5a387e439a8d5e9e38e51b488c80b025a alex <alex@amac.local> 1271951494 +0400 commit: upd
23
23
  b71b49e5a387e439a8d5e9e38e51b488c80b025a 9aa7780b0dc27b91f5c428006e587e6e2f869b72 alex <alex@amac.local> 1271951615 +0400 commit: upd
24
24
  9aa7780b0dc27b91f5c428006e587e6e2f869b72 68fe793cdcebe11f042c04a1fcf0f186abf0619e alex <alex@amac.local> 1271951787 +0400 commit: upd
25
+ 68fe793cdcebe11f042c04a1fcf0f186abf0619e a5eac8213452af3148525e98f45545fc3c7bf4b8 alex <alex@amac.local> 1274201683 +0400 commit: upd
26
+ a5eac8213452af3148525e98f45545fc3c7bf4b8 af7b16eaf5417f7996975d94ea60ef04afb511a4 alex <alex@amac.local> 1274527349 +0400 commit: upd theme
@@ -22,3 +22,5 @@ a691900cb5b7378b173ce55a29de35c18b26cd6e 5aacd2a96731620b7d13e27058b419f4dd84c81
22
22
  5aacd2a96731620b7d13e27058b419f4dd84c814 b71b49e5a387e439a8d5e9e38e51b488c80b025a alex <alex@amac.local> 1271951494 +0400 commit: upd
23
23
  b71b49e5a387e439a8d5e9e38e51b488c80b025a 9aa7780b0dc27b91f5c428006e587e6e2f869b72 alex <alex@amac.local> 1271951615 +0400 commit: upd
24
24
  9aa7780b0dc27b91f5c428006e587e6e2f869b72 68fe793cdcebe11f042c04a1fcf0f186abf0619e alex <alex@amac.local> 1271951787 +0400 commit: upd
25
+ 68fe793cdcebe11f042c04a1fcf0f186abf0619e a5eac8213452af3148525e98f45545fc3c7bf4b8 alex <alex@amac.local> 1274201683 +0400 commit: upd
26
+ a5eac8213452af3148525e98f45545fc3c7bf4b8 af7b16eaf5417f7996975d94ea60ef04afb511a4 alex <alex@amac.local> 1274527349 +0400 commit: upd theme
@@ -20,3 +20,5 @@ a691900cb5b7378b173ce55a29de35c18b26cd6e 5aacd2a96731620b7d13e27058b419f4dd84c81
20
20
  5aacd2a96731620b7d13e27058b419f4dd84c814 b71b49e5a387e439a8d5e9e38e51b488c80b025a alex <alex@amac.local> 1271951501 +0400 update by push
21
21
  b71b49e5a387e439a8d5e9e38e51b488c80b025a 9aa7780b0dc27b91f5c428006e587e6e2f869b72 alex <alex@amac.local> 1271951624 +0400 update by push
22
22
  9aa7780b0dc27b91f5c428006e587e6e2f869b72 68fe793cdcebe11f042c04a1fcf0f186abf0619e alex <alex@amac.local> 1271951793 +0400 update by push
23
+ 68fe793cdcebe11f042c04a1fcf0f186abf0619e a5eac8213452af3148525e98f45545fc3c7bf4b8 alex <alex@amac.local> 1274201690 +0400 update by push
24
+ a5eac8213452af3148525e98f45545fc3c7bf4b8 af7b16eaf5417f7996975d94ea60ef04afb511a4 alex <alex@amac.local> 1274527354 +0400 update by push
@@ -1 +1 @@
1
- 68fe793cdcebe11f042c04a1fcf0f186abf0619e
1
+ af7b16eaf5417f7996975d94ea60ef04afb511a4
@@ -1 +1 @@
1
- 68fe793cdcebe11f042c04a1fcf0f186abf0619e
1
+ af7b16eaf5417f7996975d94ea60ef04afb511a4
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ require 'fileutils'
18
18
 
19
19
  spec = Gem::Specification.new do |s|
20
20
  s.name = "ruby-ext"
21
- s.version = "0.2.13"
21
+ s.version = "0.2.15"
22
22
  s.summary = "Set of common Ruby language extensions"
23
23
  s.description = "Set of common Ruby language extensions"
24
24
  s.author = "Alexey Petrushin"
@@ -1,6 +1,6 @@
1
1
  require 'monitor'
2
2
 
3
- class Class
3
+ class Module
4
4
  def cache! *methods
5
5
  DeclarativeCache.cache! self, *methods
6
6
  end
@@ -13,160 +13,63 @@ end
13
13
  module DeclarativeCache
14
14
  DISABLED = false
15
15
 
16
- warn "CASHE DISABLED" if DISABLED
17
-
18
- @versions, @alias_counter, @monitor = Hash.new{should! :be_never_called}, 0, Monitor.new
19
- class << self
20
-
21
- def alias_counter
22
- @alias_counter += 1
23
- return :"m#{@alias_counter}"
24
- end
25
-
26
- def cache! *arg
27
- vnames, klass, methods = parse_and_check_arguments *arg
28
-
29
- return if DISABLED
30
- methods.each do |m|
31
- als = (m.to_s =~ /^[_a-zA-Z0-9]+$/) ? m : DeclarativeCache.alias_counter.to_sym
32
-
33
- klass.class_eval{alias_method :"cached_#{als}", :"#{m}"}
34
- unless vnames.is_a? Array
35
- script = single_version_without_args.interpolate binding
36
- @versions[vnames] = 0 unless @versions.include? vnames
37
- else
38
- vnames_str = vnames.collect{|vname| "'#{vname}' => nil"}.join(', ')
39
- script = multiple_version_without_args.interpolate binding
40
- vnames.each{|vname| @versions[vname] = 0 unless @versions.include? vname}
41
- end
42
- klass.class_eval script, __FILE__, __LINE__
43
- end
44
- end
45
-
46
- def cache_with_params! *arg
47
- vnames, klass, methods = parse_and_check_arguments *arg
48
-
49
- return if DISABLED
50
- methods.each do |m|
51
- als = (m.to_s =~ /^[_a-zA-Z0-9]+$/) ? m : DeclarativeCache.alias_counter
52
-
53
- klass.class_eval{alias_method :"cached_#{als}", :"#{m}"}
54
- unless vnames.is_a? Array
55
- script = single_version_with_args.interpolate binding
56
- @versions[vnames] = 0 unless @versions.include? vnames
57
- else
58
- vnames_str = vnames.collect{|vname| "'#{vname}' => nil"}.join(', ')
59
- script = multiple_version_with_args.interpolate binding
60
- vnames.each{|vname| @versions[vname] = 0 unless @versions.include? vname}
61
- end
62
- klass.class_eval script, __FILE__, __LINE__
63
- end
64
- end
65
-
66
- def version name
67
- @versions[name]
68
- end
69
-
70
- def update *names
71
- names.each do |n|
72
- n = n.to_s
73
- @versions[n] = 0 unless @versions.include? n
74
- @versions[n] += 1
75
- end
76
- end
77
-
78
- attr_reader :monitor
16
+ warn "CASHE DISABLED" if DISABLED
17
+ unless DISABLED
18
+ class << self
19
+ def alias_counter
20
+ @alias_counter ||= 0
21
+ @alias_counter += 1
22
+ return "cached_method_#{@alias_counter}"
23
+ end
79
24
 
80
- protected
81
- def parse_and_check_arguments *arg
82
- arg.size.should! :>=, 2
83
-
84
- if arg.size == 3
85
- version_names = arg.shift
86
- if version_names.is_a? Array
87
- version_names.size.should! :>, 0
88
- version_names = version_names.collect{|n| n.to_s}
89
- else
90
- version_names = version_names.to_s
25
+ def cache! klass, *methods
26
+ methods.each do |method|
27
+ klass.class_eval do
28
+ als = (method.to_s =~ /^[_a-zA-Z0-9]+$/) ? "cached_#{method}" : DeclarativeCache.alias_counter.to_sym
29
+ iv_check = "@#{als}_check"
30
+ iv = "@#{als}"
31
+
32
+ alias_method als, method
33
+
34
+ define_method method do |*args|
35
+ args.should! :be_empty
36
+ unless cached = instance_variable_get(iv)
37
+ unless check = instance_variable_get(iv_check)
38
+ cached = send als
39
+ instance_variable_set iv, cached
40
+ instance_variable_set iv_check, true
41
+ end
42
+ end
43
+ cached
44
+ end
45
+ end
91
46
  end
92
-
93
- klass = arg.shift
94
- else
95
- version_names = klass = arg.shift
96
47
  end
97
-
98
- klass.class.should! :be, [Class, Module]
99
-
100
- methods = Array(arg.first)
101
- defined = klass.instance_methods
102
- methods.each do |m|
103
- raise "Invalid method_name '#{m}'!" unless defined.include? m.to_s
104
- end
105
- return version_names, klass, methods
106
- end
107
-
108
- def multiple_version_with_args
109
- <<-RUBY
110
- def \#{m} *params
111
- DeclarativeCache.monitor.synchronize do
112
- @cache_versions_\#{als} ||= {\#{vnames_str}}
113
- @cache_value_\#{als} ||= {}
114
- if @cache_versions_\#{als}.all?{|vname, v| v == DeclarativeCache.version(vname)} and @cache_value_\#{als}.include?(params)
115
- return @cache_value_\#{als}[params]
116
- else
117
- @cache_versions_\#{als}.keys.each{|vname| @cache_versions_\#{als}[vname] = DeclarativeCache.version(vname)}
118
- return @cache_value_\#{als}[params] = cached_\#{als}(*params)
119
- end
120
- end
121
- end
122
- RUBY
123
- end
124
-
125
- def multiple_version_without_args
126
- <<-RUBY
127
- def \#{m}
128
- DeclarativeCache.monitor.synchronize do
129
- @cache_versions_\#{als} ||= {\#{vnames_str}}
130
- if @cache_versions_\#{als}.all?{|vname, v| v == DeclarativeCache.version(vname)}
131
- return @cache_value_\#{als}
132
- else
133
- @cache_versions_\#{als}.keys.each{|vname| @cache_versions_\#{als}[vname] = DeclarativeCache.version(vname)}
134
- return @cache_value_\#{als} = cached_\#{als}
135
- end
136
- end
137
- end
138
- RUBY
139
- end
140
-
141
- def single_version_with_args
142
- <<-RUBY
143
- def \#{m} *params
144
- DeclarativeCache.monitor.synchronize do
145
- @cache_value_\#{als} ||= {}
146
- if @cache_version_\#{als} == DeclarativeCache.version("\#{vnames}") and @cache_value_\#{als}.include?(params)
147
- return @cache_value_\#{als}[params]
148
- else
149
- @cache_version_\#{als} = DeclarativeCache.version("\#{vnames}")
150
- return @cache_value_\#{als}[params] = cached_\#{als}(*params)
151
- end
152
- end
153
- end
154
- RUBY
155
- end
156
-
157
- def single_version_without_args
158
- <<-RUBY
159
- def \#{m}
160
- DeclarativeCache.monitor.synchronize do
161
- if @cache_version_\#{als} == DeclarativeCache.version("\#{vnames}")
162
- return @cache_value_\#{als}
163
- else
164
- @cache_version_\#{als} = DeclarativeCache.version("\#{vnames}")
165
- return @cache_value_\#{als} = cached_\#{als}
166
- end
167
- end
168
- end
169
- RUBY
170
- end
171
- end
48
+
49
+ def cache_with_params! klass, *methods
50
+ methods.each do |method|
51
+ klass.class_eval do
52
+ als = (method.to_s =~ /^[_a-zA-Z0-9]+$/) ? "cached_#{method}" : DeclarativeCache.alias_counter.to_sym
53
+ iv = "@#{als}"
54
+
55
+ alias_method als, method
56
+
57
+ define_method method do |*args|
58
+ unless results = instance_variable_get(iv)
59
+ results = {}
60
+ instance_variable_set iv, results
61
+ end
62
+
63
+ unless results.include? args
64
+ results[args] = send als, *args
65
+ end
66
+
67
+ results[args]
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+ end
172
75
  end
@@ -0,0 +1,172 @@
1
+ require 'monitor'
2
+
3
+ class Class
4
+ def cache! *methods
5
+ DeclarativeCache.cache! self, *methods
6
+ end
7
+
8
+ def cache_with_params! *methods
9
+ DeclarativeCache.cache_with_params! self, *methods
10
+ end
11
+ end
12
+
13
+ module DeclarativeCache
14
+ DISABLED = false
15
+
16
+ warn "CASHE DISABLED" if DISABLED
17
+
18
+ @versions, @alias_counter, @monitor = Hash.new{should! :be_never_called}, 0, Monitor.new
19
+ class << self
20
+
21
+ def alias_counter
22
+ @alias_counter += 1
23
+ return :"m#{@alias_counter}"
24
+ end
25
+
26
+ def cache! *arg
27
+ vnames, klass, methods = parse_and_check_arguments *arg
28
+
29
+ return if DISABLED
30
+ methods.each do |m|
31
+ als = (m.to_s =~ /^[_a-zA-Z0-9]+$/) ? m : DeclarativeCache.alias_counter.to_sym
32
+
33
+ klass.class_eval{alias_method :"cached_#{als}", :"#{m}"}
34
+ unless vnames.is_a? Array
35
+ script = single_version_without_args.interpolate binding
36
+ @versions[vnames] = 0 unless @versions.include? vnames
37
+ else
38
+ vnames_str = vnames.collect{|vname| "'#{vname}' => nil"}.join(', ')
39
+ script = multiple_version_without_args.interpolate binding
40
+ vnames.each{|vname| @versions[vname] = 0 unless @versions.include? vname}
41
+ end
42
+ klass.class_eval script, __FILE__, __LINE__
43
+ end
44
+ end
45
+
46
+ def cache_with_params! *arg
47
+ vnames, klass, methods = parse_and_check_arguments *arg
48
+
49
+ return if DISABLED
50
+ methods.each do |m|
51
+ als = (m.to_s =~ /^[_a-zA-Z0-9]+$/) ? m : DeclarativeCache.alias_counter
52
+
53
+ klass.class_eval{alias_method :"cached_#{als}", :"#{m}"}
54
+ unless vnames.is_a? Array
55
+ script = single_version_with_args.interpolate binding
56
+ @versions[vnames] = 0 unless @versions.include? vnames
57
+ else
58
+ vnames_str = vnames.collect{|vname| "'#{vname}' => nil"}.join(', ')
59
+ script = multiple_version_with_args.interpolate binding
60
+ vnames.each{|vname| @versions[vname] = 0 unless @versions.include? vname}
61
+ end
62
+ klass.class_eval script, __FILE__, __LINE__
63
+ end
64
+ end
65
+
66
+ def version name
67
+ @versions[name]
68
+ end
69
+
70
+ def update *names
71
+ names.each do |n|
72
+ n = n.to_s
73
+ @versions[n] = 0 unless @versions.include? n
74
+ @versions[n] += 1
75
+ end
76
+ end
77
+
78
+ attr_reader :monitor
79
+
80
+ protected
81
+ def parse_and_check_arguments *arg
82
+ arg.size.should! :>=, 2
83
+
84
+ if arg.size == 3
85
+ version_names = arg.shift
86
+ if version_names.is_a? Array
87
+ version_names.size.should! :>, 0
88
+ version_names = version_names.collect{|n| n.to_s}
89
+ else
90
+ version_names = version_names.to_s
91
+ end
92
+
93
+ klass = arg.shift
94
+ else
95
+ version_names = klass = arg.shift
96
+ end
97
+
98
+ klass.class.should! :be, [Class, Module]
99
+
100
+ methods = Array(arg.first)
101
+ defined = klass.instance_methods
102
+ methods.each do |m|
103
+ raise "Invalid method_name '#{m}'!" unless defined.include? m.to_s
104
+ end
105
+ return version_names, klass, methods
106
+ end
107
+
108
+ def multiple_version_with_args
109
+ <<-RUBY
110
+ def \#{m} *params
111
+ DeclarativeCache.monitor.synchronize do
112
+ @cache_versions_\#{als} ||= {\#{vnames_str}}
113
+ @cache_value_\#{als} ||= {}
114
+ if @cache_versions_\#{als}.all?{|vname, v| v == DeclarativeCache.version(vname)} and @cache_value_\#{als}.include?(params)
115
+ return @cache_value_\#{als}[params]
116
+ else
117
+ @cache_versions_\#{als}.keys.each{|vname| @cache_versions_\#{als}[vname] = DeclarativeCache.version(vname)}
118
+ return @cache_value_\#{als}[params] = cached_\#{als}(*params)
119
+ end
120
+ end
121
+ end
122
+ RUBY
123
+ end
124
+
125
+ def multiple_version_without_args
126
+ <<-RUBY
127
+ def \#{m}
128
+ DeclarativeCache.monitor.synchronize do
129
+ @cache_versions_\#{als} ||= {\#{vnames_str}}
130
+ if @cache_versions_\#{als}.all?{|vname, v| v == DeclarativeCache.version(vname)}
131
+ return @cache_value_\#{als}
132
+ else
133
+ @cache_versions_\#{als}.keys.each{|vname| @cache_versions_\#{als}[vname] = DeclarativeCache.version(vname)}
134
+ return @cache_value_\#{als} = cached_\#{als}
135
+ end
136
+ end
137
+ end
138
+ RUBY
139
+ end
140
+
141
+ def single_version_with_args
142
+ <<-RUBY
143
+ def \#{m} *params
144
+ DeclarativeCache.monitor.synchronize do
145
+ @cache_value_\#{als} ||= {}
146
+ if @cache_version_\#{als} == DeclarativeCache.version("\#{vnames}") and @cache_value_\#{als}.include?(params)
147
+ return @cache_value_\#{als}[params]
148
+ else
149
+ @cache_version_\#{als} = DeclarativeCache.version("\#{vnames}")
150
+ return @cache_value_\#{als}[params] = cached_\#{als}(*params)
151
+ end
152
+ end
153
+ end
154
+ RUBY
155
+ end
156
+
157
+ def single_version_without_args
158
+ <<-RUBY
159
+ def \#{m}
160
+ DeclarativeCache.monitor.synchronize do
161
+ if @cache_version_\#{als} == DeclarativeCache.version("\#{vnames}")
162
+ return @cache_value_\#{als}
163
+ else
164
+ @cache_version_\#{als} = DeclarativeCache.version("\#{vnames}")
165
+ return @cache_value_\#{als} = cached_\#{als}
166
+ end
167
+ end
168
+ end
169
+ RUBY
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec'
2
+
3
+ dir = File.dirname __FILE__
4
+ require "#{dir}/spec_require"
5
+ require "#{dir}/../lib/ruby_ext/should"
6
+ require "#{dir}/../lib/ruby_ext/declarative_cache"
7
+
8
+ describe 'DeclarativeCache' do
9
+ class CachedClass
10
+ attr_accessor :value
11
+ def value_get; @value end
12
+ cache! :value_get
13
+
14
+ attr_accessor :value2
15
+ def value2_get; @value2 end
16
+
17
+ attr_accessor :params
18
+ def params_get param; @params[param] end
19
+ end
20
+
21
+ # DeclarativeCache.cache! CachedClass, :value_get
22
+ DeclarativeCache.cache! :cache_version_name, CachedClass, :value2_get
23
+ DeclarativeCache.cache_with_params! CachedClass, CachedClass, :params_get
24
+
25
+ it "Simple Cache" do
26
+ o = CachedClass.new
27
+ o.value = 0
28
+ o.value2 = 0
29
+ o.value_get.should == 0
30
+ o.value2_get.should == 0
31
+ o.value = 1
32
+ o.value2 = 1
33
+ o.value_get.should == 0
34
+ o.value2_get.should == 0
35
+ DeclarativeCache.update CachedClass
36
+ o.value_get.should == 1
37
+ o.value2_get.should == 0
38
+ DeclarativeCache.update :cache_version_name
39
+ o.value2_get.should == 1
40
+ DeclarativeCache.update CachedClass, :cache_version_name
41
+ end
42
+
43
+ it "Cache With Params" do
44
+ o = CachedClass.new
45
+ o.params = {:a => :b}
46
+ o.params_get(:a).should == :b
47
+ o.params = {:a => :c}
48
+ o.params_get(:a).should == :b
49
+ DeclarativeCache.update CachedClass
50
+ o.params_get(:a).should == :c
51
+ end
52
+
53
+ class CachedClass2
54
+ class << self
55
+ attr_accessor :value
56
+ def value_get; @value end
57
+ end
58
+ end
59
+
60
+ DeclarativeCache.cache! CachedClass2, CachedClass2.singleton_class, :value_get
61
+
62
+ it "Simple Cache" do
63
+ CachedClass2.value = 0
64
+ CachedClass2.value_get.should == 0
65
+ CachedClass2.value = 1
66
+ CachedClass2.value_get.should == 0
67
+ DeclarativeCache.update CachedClass2
68
+ CachedClass2.value_get.should == 1
69
+ end
70
+
71
+ class MultipleCacheVersions
72
+ attr_accessor :value
73
+ def value_get; @value end
74
+
75
+ attr_accessor :value2
76
+ def value2_get params; @value2 end
77
+ end
78
+
79
+ DeclarativeCache.cache! [:class, :resource_update, :security_update], MultipleCacheVersions, :value_get
80
+ DeclarativeCache.cache_with_params! [:class, :resource_update, :security_update], MultipleCacheVersions, :value2_get
81
+
82
+ it "Multiple cache versions" do
83
+ o = MultipleCacheVersions.new
84
+ o.value, o.value2 = 0, 0
85
+
86
+ o.value_get.should == 0
87
+ o.value = 1
88
+ o.value_get.should == 0
89
+ DeclarativeCache.update :class
90
+ o.value_get.should == 1
91
+ o.value = 2
92
+ o.value_get.should == 1
93
+ DeclarativeCache.update :resource_update, :security_update
94
+ o.value_get.should == 2
95
+
96
+ o.value2_get("params").should == 0
97
+ end
98
+ end
@@ -12,32 +12,37 @@ describe 'DeclarativeCache' do
12
12
  cache! :value_get
13
13
 
14
14
  attr_accessor :value2
15
- def value2_get; @value2 end
15
+ def value2_get; @value2 end
16
16
 
17
17
  attr_accessor :params
18
18
  def params_get param; @params[param] end
19
+
20
+ attr_accessor :multiplier
21
+ def *(arg)
22
+ @multiplier * arg
23
+ end
24
+ cache_with_params! '*'
19
25
  end
20
26
 
21
- # DeclarativeCache.cache! CachedClass, :value_get
22
- DeclarativeCache.cache! :cache_version_name, CachedClass, :value2_get
23
- DeclarativeCache.cache_with_params! CachedClass, CachedClass, :params_get
27
+ DeclarativeCache.cache! CachedClass, :value2_get
28
+ DeclarativeCache.cache_with_params! CachedClass, :params_get
24
29
 
25
30
  it "Simple Cache" do
26
31
  o = CachedClass.new
27
32
  o.value = 0
28
- o.value2 = 0
33
+ o.value2 = 0
29
34
  o.value_get.should == 0
30
35
  o.value2_get.should == 0
36
+
31
37
  o.value = 1
32
38
  o.value2 = 1
33
39
  o.value_get.should == 0
34
40
  o.value2_get.should == 0
35
- DeclarativeCache.update CachedClass
36
- o.value_get.should == 1
37
- o.value2_get.should == 0
38
- DeclarativeCache.update :cache_version_name
39
- o.value2_get.should == 1
40
- DeclarativeCache.update CachedClass, :cache_version_name
41
+ end
42
+
43
+ it "should check for parameters" do
44
+ o = CachedClass.new
45
+ lambda{o.value_get(1)}.should raise_error(AssertionError)
41
46
  end
42
47
 
43
48
  it "Cache With Params" do
@@ -46,8 +51,14 @@ describe 'DeclarativeCache' do
46
51
  o.params_get(:a).should == :b
47
52
  o.params = {:a => :c}
48
53
  o.params_get(:a).should == :b
49
- DeclarativeCache.update CachedClass
50
- o.params_get(:a).should == :c
54
+ end
55
+
56
+ it "should works with operators" do
57
+ o = CachedClass.new
58
+ o.multiplier = 2
59
+ (o * 2).should == 4
60
+ o.multiplier = 3
61
+ (o * 2).should == 4
51
62
  end
52
63
 
53
64
  class CachedClass2
@@ -57,42 +68,33 @@ describe 'DeclarativeCache' do
57
68
  end
58
69
  end
59
70
 
60
- DeclarativeCache.cache! CachedClass2, CachedClass2.singleton_class, :value_get
71
+ DeclarativeCache.cache! CachedClass2.singleton_class, :value_get
61
72
 
62
73
  it "Simple Cache" do
63
74
  CachedClass2.value = 0
64
75
  CachedClass2.value_get.should == 0
65
76
  CachedClass2.value = 1
66
77
  CachedClass2.value_get.should == 0
67
- DeclarativeCache.update CachedClass2
68
- CachedClass2.value_get.should == 1
69
78
  end
70
79
 
71
- class MultipleCacheVersions
72
- attr_accessor :value
73
- def value_get; @value end
74
-
75
- attr_accessor :value2
76
- def value2_get params; @value2 end
80
+ module CachedModule
81
+ attr_accessor :value
82
+ def value_get; @value end
83
+ cache! :value_get
77
84
  end
78
85
 
79
- DeclarativeCache.cache! [:class, :resource_update, :security_update], MultipleCacheVersions, :value_get
80
- DeclarativeCache.cache_with_params! [:class, :resource_update, :security_update], MultipleCacheVersions, :value2_get
86
+ class CachedClass3
87
+ include CachedModule
88
+ end
81
89
 
82
- it "Multiple cache versions" do
83
- o = MultipleCacheVersions.new
84
- o.value, o.value2 = 0, 0
85
-
90
+ it "should also works with modules (from error)" do
91
+ o = CachedClass.new
92
+ o.value = 0
86
93
  o.value_get.should == 0
87
- o.value = 1
88
- o.value_get.should == 0
89
- DeclarativeCache.update :class
90
- o.value_get.should == 1
91
- o.value = 2
92
- o.value_get.should == 1
93
- DeclarativeCache.update :resource_update, :security_update
94
- o.value_get.should == 2
95
94
 
96
- o.value2_get("params").should == 0
95
+ o.value = 1
96
+ o.value_get.should == 0
97
97
  end
98
+
99
+
98
100
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ext
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 9
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 13
9
- version: 0.2.13
9
+ - 15
10
+ version: 0.2.15
10
11
  platform: ruby
11
12
  authors:
12
13
  - Alexey Petrushin
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-22 00:00:00 +04:00
18
+ date: 2010-05-22 00:00:00 +04:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -32,6 +33,7 @@ files:
32
33
  - .gitignore
33
34
  - lib/ruby_ext/class.rb
34
35
  - lib/ruby_ext/declarative_cache.rb
36
+ - lib/ruby_ext/declarative_cache_rem.rb
35
37
  - lib/ruby_ext/file.rb
36
38
  - lib/ruby_ext/kernel.rb
37
39
  - lib/ruby_ext/module.rb
@@ -44,6 +46,7 @@ files:
44
46
  - lib/ruby_ext/symbol.rb
45
47
  - lib/ruby_ext/synchronizer.rb
46
48
  - lib/ruby_ext.rb
49
+ - spec/declarative_cache_rem.rb
47
50
  - spec/declarative_cache_spec.rb
48
51
  - spec/kernel_spec.rb
49
52
  - spec/module_spec.rb
@@ -191,6 +194,7 @@ files:
191
194
  - .git/objects/37/56676bcca271d513748813326b9d1cb06289b6
192
195
  - .git/objects/38/91f271b22f2a1caee6910a34139076e27ade00
193
196
  - .git/objects/38/bf6dbb2520b448e08ac9cb353523bbc72118db
197
+ - .git/objects/39/68c39a1aef71d8e76f7c456a05677682c6499f
194
198
  - .git/objects/3a/5fe0dc6aaa6e41eb8dd865fa7d7100f4e68ced
195
199
  - .git/objects/3b/203741a23f9eb3df39a0444c4c5a4469a89c51
196
200
  - .git/objects/40/36a1a67f1217086c5d1519ecd6bc6c85172513
@@ -208,6 +212,7 @@ files:
208
212
  - .git/objects/55/64bf7edfff421a8a139bc630311a999e9187df
209
213
  - .git/objects/55/a433dd00ba298006a2fc028964eb0cde7c2e5b
210
214
  - .git/objects/55/f338afb8c82f8cad38b28d0e8cf887f9bda1ce
215
+ - .git/objects/56/b6a807e230b2761d6514d2a59c224c85ab5a52
211
216
  - .git/objects/57/64ef3e607d3570146219cd858a1dd4afb24ea5
212
217
  - .git/objects/57/ab6c10ddf4eff75d98b5770a2c2bf573b692cd
213
218
  - .git/objects/57/cf2479bb9c6e31118c42c5cceaffada1862c72
@@ -215,6 +220,7 @@ files:
215
220
  - .git/objects/59/653cefe5b174e4a7002100f024448cdb337373
216
221
  - .git/objects/59/f04835f47642d357c730bd445cfb6d81e977c2
217
222
  - .git/objects/5a/acd2a96731620b7d13e27058b419f4dd84c814
223
+ - .git/objects/5b/a4b75e6d01fa66089b277f32ae8d7b131fb3bc
218
224
  - .git/objects/5c/28c251bb201232470340d73ed4cc4926cd241d
219
225
  - .git/objects/5c/536c5d712f7cf34e21be5526aa3e826888810f
220
226
  - .git/objects/5d/281b39340e5d448c63c8f439c9ca4035ccaf66
@@ -261,6 +267,7 @@ files:
261
267
  - .git/objects/98/359366defef2b74ad1f641f1f237f284d663e2
262
268
  - .git/objects/99/3591274b3b946f334d086b62dfca5bc904d810
263
269
  - .git/objects/9a/a7780b0dc27b91f5c428006e587e6e2f869b72
270
+ - .git/objects/9b/0d15c99ac3c232baf2e73aea045bc1d9f06868
264
271
  - .git/objects/9c/d9497bad03afd65531dda2695719b3593e02b6
265
272
  - .git/objects/9e/a37d9fc7e1ad1504b50da2a1ec639c523fb8b7
266
273
  - .git/objects/9f/9a4ebb6d3b4f75ebebc57119b2cf61606d4685
@@ -269,6 +276,8 @@ files:
269
276
  - .git/objects/a4/45fcc1f4c5646c1fbd51d5fda9a69ccceeca76
270
277
  - .git/objects/a4/ab487fcb12cfb831b09c525544f52d60a98598
271
278
  - .git/objects/a4/d0f078375c5b39cee3083ad428912698777c7b
279
+ - .git/objects/a5/b6b4cfee2941c3b3407c4e5a4a17252f7cc22c
280
+ - .git/objects/a5/eac8213452af3148525e98f45545fc3c7bf4b8
272
281
  - .git/objects/a6/91900cb5b7378b173ce55a29de35c18b26cd6e
273
282
  - .git/objects/a7/eab1d126c7e7e7d24c3a4159abe4e15a5c02fe
274
283
  - .git/objects/a9/2112f979b22837fa6d3d39829eff7c3fd34947
@@ -276,8 +285,11 @@ files:
276
285
  - .git/objects/ad/09237b6008fc0ebfb9b8c920490dda8503bfd1
277
286
  - .git/objects/ad/7462077a480cb995d1ad397c3c737644e59887
278
287
  - .git/objects/ad/e1a70e7cf984a2f518d19ef625362d78a5fbd0
288
+ - .git/objects/af/7b16eaf5417f7996975d94ea60ef04afb511a4
279
289
  - .git/objects/b0/d1bed68f91428a83ef698b448a19d74638bfc5
290
+ - .git/objects/b1/3a5d436847be255094b5e0b6e98e1af8896fc0
280
291
  - .git/objects/b2/07485e0a3aabbdae649837d2a50b95194a33fa
292
+ - .git/objects/b2/74f04a19b6956620fbf528af41e31b56511781
281
293
  - .git/objects/b4/cbb05893636d6b7314fbc4df7e3a8dcaeb0de1
282
294
  - .git/objects/b6/17a8cc2ae7f6ea496051db493aa56edc178073
283
295
  - .git/objects/b6/863b5d4c0a4d87b81a9bbc29e786fcf7ef0df2
@@ -296,6 +308,7 @@ files:
296
308
  - .git/objects/c9/b54c8eb8731073db446ff8be40ad01db6729be
297
309
  - .git/objects/c9/c39c710d4de2a46c0ed97985641c2b8e4533a2
298
310
  - .git/objects/ca/9716fd518aac44d4acaa94a86838cde6030f6a
311
+ - .git/objects/cb/2c5717c69e0f21c6486fd6bf5656c0c7e13757
299
312
  - .git/objects/d0/4df35cc5f148c409cf89ecf56aaec49b232731
300
313
  - .git/objects/d0/96982b098278550168750565c9db623fdf8670
301
314
  - .git/objects/d0/b6eae8243889753a5a3e9a801b4dd5bcd09d91
@@ -326,6 +339,7 @@ files:
326
339
  - .git/objects/f7/c0fa5621b81aca548c738c08907055696e1956
327
340
  - .git/objects/f8/c960b12cbddb90f18123673e6778efdc822058
328
341
  - .git/objects/fa/8df3e916f0af98b6439ebdd73253f97cd2c172
342
+ - .git/objects/fb/4b373a26b54cdcbaaded432ea41cada57b840f
329
343
  - .git/objects/fb/85b5793dcebae826b04cd8c37406504540d8a4
330
344
  - .git/objects/fd/305b4d657d487e6f5f69c760b8d433d16f6a47
331
345
  - .git/objects/fd/d3ef7ec06e804f3688491e21caaa4d89796b16
@@ -347,23 +361,27 @@ rdoc_options: []
347
361
  require_paths:
348
362
  - lib
349
363
  required_ruby_version: !ruby/object:Gem::Requirement
364
+ none: false
350
365
  requirements:
351
366
  - - ">="
352
367
  - !ruby/object:Gem::Version
368
+ hash: 3
353
369
  segments:
354
370
  - 0
355
371
  version: "0"
356
372
  required_rubygems_version: !ruby/object:Gem::Requirement
373
+ none: false
357
374
  requirements:
358
375
  - - ">="
359
376
  - !ruby/object:Gem::Version
377
+ hash: 3
360
378
  segments:
361
379
  - 0
362
380
  version: "0"
363
381
  requirements: []
364
382
 
365
383
  rubyforge_project:
366
- rubygems_version: 1.3.6
384
+ rubygems_version: 1.3.7
367
385
  signing_key:
368
386
  specification_version: 3
369
387
  summary: Set of common Ruby language extensions