click 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/click/clicker.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'click/indeterminable'
2
+
1
3
  module Click
2
4
  class Clicker
3
5
  def click!
@@ -9,9 +11,9 @@ module Click
9
11
  ObjectSpace.each_object do |object|
10
12
  begin
11
13
  klass = object.class
12
- next unless klass.is_a?(Class)
14
+ klass = Click::Indeterminable unless klass.is_a?(Class)
13
15
  rescue NoMethodError
14
- next
16
+ klass = Click::Indeterminable
15
17
  end
16
18
 
17
19
  @state[klass] += 1
@@ -19,12 +19,14 @@ module Click
19
19
  private
20
20
  def _with_db(db)
21
21
  ensure_tables!(db)
22
- Sequel::Model.db = db
23
- require 'click/database/models'
22
+ assign_db_to_models(db)
24
23
  yield db
25
- ensure
26
- db = nil
27
- Sequel::Model.db = nil
24
+ end
25
+
26
+ def assign_db_to_models(db)
27
+ require 'click/database/models'
28
+ Click::Database::Models::Snapshot.db = db
29
+ Click::Database::Models::ObjectCount.db = db
28
30
  end
29
31
 
30
32
  def ensure_tables!(db)
@@ -0,0 +1,4 @@
1
+ module Click
2
+ class Indeterminable < BasicObject
3
+ end
4
+ end
data/lib/click/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Click
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/clicker_spec.rb CHANGED
@@ -31,6 +31,35 @@ describe Click::Clicker do
31
31
  clicker.instance_count(Symbol)
32
32
  }.by_at_least(difference)
33
33
  end
34
+
35
+ it 'counts BasicObjects as indeterminable' do
36
+ difference = 100
37
+ stuff = []
38
+
39
+ expect {
40
+ difference.times { |i| stuff << BasicObject.new }
41
+ }.to change {
42
+ clicker.click!
43
+ clicker.instance_count(Click::Indeterminable)
44
+ }.by_at_least(difference)
45
+ end
46
+
47
+ it 'counts objects that have overridden #class as indeterminable' do
48
+ difference = 100
49
+ stuff = []
50
+ klass = Class.new do
51
+ def class
52
+ nil
53
+ end
54
+ end
55
+
56
+ expect {
57
+ difference.times { |i| stuff << klass.new }
58
+ }.to change {
59
+ clicker.click!
60
+ clicker.instance_count(Click::Indeterminable)
61
+ }.by_at_least(difference)
62
+ end
34
63
  end
35
64
 
36
65
  describe '#object_counts' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: click
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -131,6 +131,7 @@ files:
131
131
  - lib/click/database/models/object_count.rb
132
132
  - lib/click/database/models/snapshot.rb
133
133
  - lib/click/database/writer.rb
134
+ - lib/click/indeterminable.rb
134
135
  - lib/click/observer.rb
135
136
  - lib/click/version.rb
136
137
  - spec/click_spec.rb