benelux 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +6 -0
- data/benelux.gemspec +1 -1
- data/lib/benelux/packer.rb +9 -6
- data/lib/benelux.rb +7 -53
- data/lib/selectable/object.rb +1 -1
- data/lib/selectable/tags.rb +5 -1
- data/lib/selectable.rb +12 -5
- data/tryouts/11_selectable_tryouts.rb +0 -4
- metadata +1 -1
data/CHANGES.txt
CHANGED
data/benelux.gemspec
CHANGED
data/lib/benelux/packer.rb
CHANGED
@@ -45,7 +45,12 @@ module Benelux
|
|
45
45
|
self.add_tags :class => @klass.to_s.to_sym,
|
46
46
|
:meth => @meth.to_sym,
|
47
47
|
:kind => self.class.to_s.to_sym
|
48
|
-
|
48
|
+
|
49
|
+
Benelux.packed_methods[@klass] ||= {}
|
50
|
+
Benelux.packed_methods[@klass][@meth] = self
|
51
|
+
Benelux.packed_methods[:all] ||= []
|
52
|
+
Benelux.packed_methods[:all] << self
|
53
|
+
|
49
54
|
end
|
50
55
|
def install_method
|
51
56
|
raise "You need to implement this method"
|
@@ -76,7 +81,7 @@ module Benelux
|
|
76
81
|
# generate_method. It calls <tt>@klass.module_eval</tt>
|
77
82
|
# with the modified line number (helpful for exceptions)
|
78
83
|
def install_method
|
79
|
-
@klass.module_eval generate_packed_method, __FILE__,
|
84
|
+
@klass.module_eval generate_packed_method, __FILE__, 94
|
80
85
|
end
|
81
86
|
|
82
87
|
# Creates a method definition (for an eval). The
|
@@ -109,17 +114,15 @@ module Benelux
|
|
109
114
|
class MethodCounter < MethodPacker
|
110
115
|
attr_reader :counter
|
111
116
|
def install_method
|
112
|
-
@klass.module_eval generate_packed_method, __FILE__,
|
117
|
+
@klass.module_eval generate_packed_method, __FILE__, 122
|
113
118
|
end
|
114
119
|
|
115
120
|
def generate_packed_method(callblock=false)
|
116
121
|
%Q{
|
117
|
-
@@__benelux_#{@meth}_counter =
|
118
|
-
Benelux.counted_method #{@klass}, :#{@meth}
|
119
122
|
def #{@meth}(*args, &block)
|
120
123
|
Benelux.current_track :global unless Benelux.known_thread?
|
121
124
|
# Get a reference to this MethodCounter instance
|
122
|
-
cmd = Benelux.
|
125
|
+
cmd = Benelux.packed_method #{@klass}, :#{@meth}
|
123
126
|
ret = #{@aliaz}(*args, &block)
|
124
127
|
count = cmd.determine_count(args, ret)
|
125
128
|
Benelux.ld "COUNT(:#{@meth}): \#{count}"
|
data/lib/benelux.rb
CHANGED
@@ -5,7 +5,7 @@ require 'thwait'
|
|
5
5
|
require 'selectable'
|
6
6
|
|
7
7
|
module Benelux
|
8
|
-
VERSION = "0.4.
|
8
|
+
VERSION = "0.4.2"
|
9
9
|
NOTSUPPORTED = [Class, Object, Kernel]
|
10
10
|
|
11
11
|
class BeneluxError < RuntimeError; end
|
@@ -32,7 +32,7 @@ module Benelux
|
|
32
32
|
attr_reader :reporter
|
33
33
|
end
|
34
34
|
|
35
|
-
@packed_methods =
|
35
|
+
@packed_methods = {}
|
36
36
|
@tracks = SelectableHash.new
|
37
37
|
@timeline = Timeline.new
|
38
38
|
@reporter = Reporter.new
|
@@ -93,22 +93,13 @@ module Benelux
|
|
93
93
|
def Benelux.inspect
|
94
94
|
str = ["Benelux"]
|
95
95
|
str << "tracks:" << Benelux.tracks.inspect
|
96
|
-
str << "timers:" << Benelux.timed_methods.inspect
|
97
|
-
#str << "timeline:" << Benelux.timeline.inspect
|
98
96
|
str.join $/
|
99
97
|
end
|
100
98
|
|
101
99
|
def Benelux.supported?(klass)
|
102
100
|
!NOTSUPPORTED.member?(klass)
|
103
101
|
end
|
104
|
-
|
105
|
-
def Benelux.timed_methods
|
106
|
-
Benelux.packed_methods.filter :kind => :'Benelux::MethodTimer'
|
107
|
-
end
|
108
102
|
|
109
|
-
def Benelux.counted_methods
|
110
|
-
Benelux.packed_methods.filter :kind => :'Benelux::MethodCounter'
|
111
|
-
end
|
112
103
|
|
113
104
|
def Benelux.known_thread?(t=Thread.current)
|
114
105
|
@reporter.thwait.threads.member? t
|
@@ -123,35 +114,17 @@ module Benelux
|
|
123
114
|
end
|
124
115
|
|
125
116
|
def Benelux.packed_method(klass, meth)
|
126
|
-
Benelux.packed_methods
|
127
|
-
|
128
|
-
|
129
|
-
def Benelux.counted_method(klass, meth)
|
130
|
-
Benelux.counted_methods.filter(klass.to_s.to_sym, meth).first
|
117
|
+
return nil unless defined?(Benelux.packed_methods[klass][meth])
|
118
|
+
Benelux.packed_methods[klass][meth]
|
131
119
|
end
|
132
120
|
|
133
|
-
def Benelux.
|
134
|
-
Benelux.
|
121
|
+
def Benelux.packed_method? klass, meth
|
122
|
+
!Benelux.packed_method(klass, meth).nil?
|
135
123
|
end
|
136
124
|
|
137
|
-
def Benelux.timed_method? klass, meth
|
138
|
-
Benelux.packed_method? klass, meth, :'Benelux::MethodTimer'
|
139
|
-
end
|
140
|
-
|
141
|
-
def Benelux.counted_method? klass, meth
|
142
|
-
Benelux.packed_method? klass, meth, :'Benelux::MethodCounter'
|
143
|
-
end
|
144
|
-
|
145
|
-
def Benelux.packed_method? klass, meth, kind=nil
|
146
|
-
list = Benelux.packed_methods.filter(klass.to_s.to_sym, meth)
|
147
|
-
list.filter! :kind => kind unless kind.nil?
|
148
|
-
!list.empty?
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
125
|
def Benelux.add_timer klass, meth, &blk
|
153
126
|
raise NotSupported, klass unless Benelux.supported? klass
|
154
|
-
raise AlreadyTimed, klass if Benelux.
|
127
|
+
raise AlreadyTimed, klass if Benelux.packed_method? klass, meth
|
155
128
|
Benelux::MethodTimer.new klass, meth, &blk
|
156
129
|
end
|
157
130
|
|
@@ -163,25 +136,6 @@ module Benelux
|
|
163
136
|
def Benelux.ld(*msg)
|
164
137
|
@@logger.puts "D: " << msg.join("#{$/}D: ") if debug?
|
165
138
|
end
|
166
|
-
|
167
|
-
|
168
|
-
# Returns an Array of method names for the current class that
|
169
|
-
# are timed by Benelux.
|
170
|
-
#
|
171
|
-
# This is an instance method for objects which have Benelux
|
172
|
-
# modified methods.
|
173
|
-
def timed_methods
|
174
|
-
Benelux.timed_methods.filter(:class => self.class.to_s.to_sym)
|
175
|
-
end
|
176
|
-
|
177
|
-
# Returns an Array of method names for the current class that
|
178
|
-
# are counted by Benelux.
|
179
|
-
#
|
180
|
-
# This is an instance method for objects which have Benelux
|
181
|
-
# modified methods.
|
182
|
-
def counted_methods
|
183
|
-
Benelux.counted_methods.filter(:class => self.class.to_s.to_sym)
|
184
|
-
end
|
185
139
|
|
186
140
|
|
187
141
|
def Benelux.enable_debug; @@debug = true; end
|
data/lib/selectable/object.rb
CHANGED
data/lib/selectable/tags.rb
CHANGED
@@ -31,7 +31,11 @@ module Selectable
|
|
31
31
|
|
32
32
|
def ==(other)
|
33
33
|
if other.is_a?(Array)
|
34
|
-
|
34
|
+
# NOTE: This resolves the issue of sorting an Array
|
35
|
+
# with a mix of Object types (Integers, Strings, Symbols).
|
36
|
+
# As in: self.values.sort == other.sort)
|
37
|
+
(self.values.size == other.size) &&
|
38
|
+
(self.values - other).empty?
|
35
39
|
else
|
36
40
|
super(other)
|
37
41
|
end
|
data/lib/selectable.rb
CHANGED
@@ -20,11 +20,15 @@ module Selectable
|
|
20
20
|
def Selectable.normalize(*tags)
|
21
21
|
tags.flatten!
|
22
22
|
tags = tags.first if tags.first.kind_of?(Hash) || tags.first.kind_of?(Array)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# NOTE: The string enforcement is disabled
|
24
|
+
# FOR NOW.
|
25
|
+
#if tags.is_a?(Hash)
|
26
|
+
# #tmp = {}
|
27
|
+
# #tags.each_pair { |n,v| tmp[n] = v.to_s }
|
28
|
+
# #tags = tmp
|
29
|
+
#else
|
30
|
+
# tags.collect! { |v| v.to_s }
|
31
|
+
#end
|
28
32
|
tags
|
29
33
|
end
|
30
34
|
|
@@ -38,6 +42,9 @@ module Selectable
|
|
38
42
|
#
|
39
43
|
# undefined method `>=' for nil:NilClass
|
40
44
|
#
|
45
|
+
# It also means you need be aware of the types
|
46
|
+
# of objects you are storing as values. If you
|
47
|
+
# store a Symbol, you must send a Symbol here.
|
41
48
|
def filter(*tags)
|
42
49
|
tags = Selectable.normalize tags
|
43
50
|
# select returns an Array. We want a Selectable.
|
@@ -22,10 +22,6 @@ tryouts "Selectable" do
|
|
22
22
|
base.filter(:even => true)
|
23
23
|
end
|
24
24
|
|
25
|
-
drill "[] and filter are the same", true do
|
26
|
-
base.filter(:even => false) == base.filter(:even => false)
|
27
|
-
end
|
28
|
-
|
29
25
|
dream :class, SelectableArray
|
30
26
|
dream :object_id, base.object_id
|
31
27
|
dream :size, 5
|