object_tracker 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a059858f4b2035c15ff8c845c537b3a5731d8cba
4
- data.tar.gz: 361ea1ca3cbdacec35bb28c871976ad5d3a103b7
3
+ metadata.gz: 87e38e45c8d6bb9872888530e0a0f7cc4de8bd69
4
+ data.tar.gz: 5bc4f026027c89e0db0f1364221217534496ed4c
5
5
  SHA512:
6
- metadata.gz: b07a26e80d2f4279df58e1956ffb675f5a3b5a9184c9f81bee6d88173f8b4dca793ee782c92e40230bbdb26429766189490aa47f3c112c28f2111d0c910dadbb
7
- data.tar.gz: 0d7137d415304e83df80352d251c52185a31fd23bd5778b61c8df5619c6e8d59c109e0e411a90e013d1a38bb7ba256ad0dc50276026abb02b9a53aa94909b96a
6
+ metadata.gz: 9302bad570cb193fde06f0dca7793179e10a2e41dfee6a7d4853bb41729aaeacdae7909484dbc709681c1a4800c21ee1faba6bec61846576d49327d8b9fea596
7
+ data.tar.gz: 02d75cc428385665bd4173c201011c050ba27d7a8721f188788fc98b09f18e7f8b36109bd2a6aaf0043402e9989cc419a7acdbd21b976566d05a0e4d83491dca
data/bin/console.rb ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pp'
5
+ require 'object_tracker'
6
+ require 'irb'
7
+
8
+ class Wut
9
+ extend ObjectTracker
10
+
11
+ def initialize
12
+ @data = []
13
+ @info = { name: 'foo', weight: 20 }
14
+ end
15
+
16
+ def to_s
17
+ end
18
+ track_all!
19
+ end
20
+
21
+ IRB.start
@@ -1,8 +1,6 @@
1
1
  require 'benchmark'
2
2
  require 'object_tracker/version'
3
3
 
4
- fail "ObjectTracker #{ObjectTracker::VERSION} only supports Ruby 2+" if RUBY_VERSION < '2.0.0'
5
-
6
4
  module ObjectTracker
7
5
  def track(*args)
8
6
  args.each do |method_name|
@@ -77,9 +75,11 @@ module ObjectTracker
77
75
  RUBY
78
76
 
79
77
  # Handle both instance and class level extension
80
- if respond_to?(:prepend)
78
+ if Class === self.class
79
+ prepend(Inspector)
81
80
  prepend(mod)
82
81
  else
82
+ extend(Inspector)
83
83
  extend(mod)
84
84
  end
85
85
  end
@@ -101,11 +101,11 @@ module ObjectTracker
101
101
  end
102
102
 
103
103
  def track_reserved_methods
104
- @__reserved_methods ||= (defined?(Rails) ? [:default_scope, :base_class, :superclass, :<, :current_scope=] : [])
105
- end
106
-
107
- def tracked_calls
108
- @__tracked_calls
104
+ @__reserved_methods ||= begin
105
+ names = [:__send__, :object_id]
106
+ names.concat [:default_scope, :base_class, :superclass, :<, :current_scope=] if defined?(Rails)
107
+ names
108
+ end
109
109
  end
110
110
 
111
111
  class UntrackableMethod < StandardError
@@ -113,4 +113,12 @@ module ObjectTracker
113
113
  super "Can't track :#{method_name} because it's not defined on this class or it's instance"
114
114
  end
115
115
  end
116
+
117
+ module Inspector
118
+ def inspect
119
+ ivars = instance_variables - [:@__tracking, :@__tracked_calls, :@__reserved_methods]
120
+ vars = ivars.map { |ivar| ivar.to_s + "=" + instance_variable_get(ivar).to_s }
121
+ %Q(#<#{self.class.name}:#{object_id}(tracking)#{' ' if vars.any? }#{vars.join(', ')}>)
122
+ end
123
+ end
116
124
  end
@@ -1,3 +1,3 @@
1
1
  module ObjectTracker
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.10"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.required_ruby_version = '>= 2.0.0'
23
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-29 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,7 +42,8 @@ description: Track method calls to almost any object. Class and instance methods
42
42
  be tracked (w/ arguments).
43
43
  email:
44
44
  - arebuckley@gmail.com
45
- executables: []
45
+ executables:
46
+ - console.rb
46
47
  extensions: []
47
48
  extra_rdoc_files: []
48
49
  files:
@@ -51,6 +52,7 @@ files:
51
52
  - LICENSE.txt
52
53
  - README.md
53
54
  - Rakefile
55
+ - bin/console.rb
54
56
  - lib/object_tracker.rb
55
57
  - lib/object_tracker/version.rb
56
58
  - object_tracker.gemspec
@@ -66,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
68
  requirements:
67
69
  - - ">="
68
70
  - !ruby/object:Gem::Version
69
- version: '0'
71
+ version: 2.0.0
70
72
  required_rubygems_version: !ruby/object:Gem::Requirement
71
73
  requirements:
72
74
  - - ">="