putter 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +18 -3
- data/lib/putter/configuration.rb +17 -6
- data/lib/putter/errors.rb +6 -0
- data/lib/putter/follower.rb +1 -1
- data/lib/putter/follower_data.rb +14 -7
- data/lib/putter/method_creator.rb +2 -12
- data/lib/putter/version.rb +1 -1
- data/lib/putter/watcher.rb +1 -1
- data/lib/putter/watcher_data.rb +10 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e5d9857773568b7246fa5399bdbdfad54bfbd96
|
4
|
+
data.tar.gz: be5caaf99f8666322b70cde787ecffac3477cad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dd17629db6f833c3146b0ae63219fb5479b2025474fad5ee12218a21a019a6a762e7b878144dc9ddc1106feb8b461524291b3cca74301d46f93cd655d513dd2
|
7
|
+
data.tar.gz: d60e579a5c7ef5d5926afca2941937fd9eb3d2f15babe8e3ecdf399a1d342b74cd8e4eef7d8158ceb7a9678c6cf63f5aac5bef9523700b96d37f3a0bc4e77740
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# CHANGELOG
|
2
|
+
### 0.5.0 - 2016-11-10
|
3
|
+
- Add methods blacklist to the configuration options
|
4
|
+
- Ensures that local method options override anything in the blacklist
|
5
|
+
|
2
6
|
### 0.4.1 - 2016-10-16
|
3
7
|
- By default, Putter will not run in production mode in Rails, this can be allow via configuration
|
4
8
|
- By default, Putter will ignore methods from ActiveRecord::Base if it is present
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -60,8 +60,11 @@ Putter Debugging: Object instance ./putter/README.md:57 -- Method: :hello, Args:
|
|
60
60
|
```ruby
|
61
61
|
Putter.follow(
|
62
62
|
object_to_follow,
|
63
|
-
label: "My object", # Optional - Label to use after "Putter Debugging: My object".
|
64
|
-
|
63
|
+
label: "My object", # Optional - Label to use after "Putter Debugging: My object".
|
64
|
+
# Will be "ClassName" for classes or "ClassName instance" for instances
|
65
|
+
methods: ["my_method"], # Optional - If array is empty, then all methods will be watched.
|
66
|
+
# Otherwise, this is an array of methods to print debugging input for. This will override
|
67
|
+
# any settings in the configuration blacklist
|
65
68
|
)
|
66
69
|
```
|
67
70
|
|
@@ -102,7 +105,9 @@ Putter Debugging: MyObject instance 1 ./putter/README.md:97 -- Method: :hello_in
|
|
102
105
|
Putter.watch(
|
103
106
|
ClassToWatch,
|
104
107
|
label: "My class", # Optional - Label to use after "Putter Debugging: My class". Will be "ClassName" for classes or "ClassName instance #" for instances
|
105
|
-
methods: ["my_method"], # Optional - If array is empty, then all methods will be watched.
|
108
|
+
methods: ["my_method"], # Optional - If array is empty, then all methods will be watched.
|
109
|
+
# Otherwise, this is an array of methods to print debugging input for. This will override
|
110
|
+
# any settings in the configuration blacklist
|
106
111
|
)
|
107
112
|
```
|
108
113
|
|
@@ -116,6 +121,7 @@ Putter.configure do |config|
|
|
116
121
|
# method, args string, and result respectively. This block will be used after each method
|
117
122
|
# is called, it must contain puts or logger calls, to print or any other method callbacks
|
118
123
|
# that are helpful.
|
124
|
+
|
119
125
|
# Defaults to Putter::PrintStrategy::Default
|
120
126
|
config.print_strategy = Proc.new do |data|
|
121
127
|
puts "#{data.line} - Label: #{data.label}, Method: #{data.method}, Args: #{data.args}, Result: #{data.result}"
|
@@ -123,17 +129,26 @@ Putter.configure do |config|
|
|
123
129
|
|
124
130
|
# "ignore_methods_from" takes an array of class names and will ignore both class and instance methods
|
125
131
|
# from those classes when adding methods to the proxy and adding debug output
|
132
|
+
|
126
133
|
# Defaults to [Object] or [Object, ActiveRecord::Based] if defined
|
127
134
|
config.ignore_methods_from = [Object, ActiveRecord::Base]
|
128
135
|
|
129
136
|
# "methods_whitelist" takes an array of methods and will always proxy and debug those methods
|
130
137
|
# regardless of whether or not the class is ignored and regardless of what methods are passed
|
131
138
|
# in when running "Putter.follow" or "Putter.watch"
|
139
|
+
|
132
140
|
# Defaults to []
|
133
141
|
config.methods_whitelist = [:to_s]
|
134
142
|
|
143
|
+
# "methods_blacklist" takes an array of methods and will never proxy. If this is combined
|
144
|
+
# with the `methods_whitelist` then it will raise a `MethodConflictError`.
|
145
|
+
|
146
|
+
# Defaults to []
|
147
|
+
config.methods_blacklist = [:to_s]
|
148
|
+
|
135
149
|
# "allow_production" takes a boolean and determines whether or not Putter will run if
|
136
150
|
# `Rails.env == "production"`
|
151
|
+
|
137
152
|
# Defaults to false
|
138
153
|
config.allow_production = false
|
139
154
|
end
|
data/lib/putter/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Putter
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :
|
4
|
-
attr_writer :ignore_methods_from
|
3
|
+
attr_accessor :allow_production, :methods_whitelist, :methods_blacklist, :print_strategy
|
4
|
+
attr_writer :ignore_methods_from
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@ignore_methods_from = [Object]
|
@@ -9,17 +9,28 @@ module Putter
|
|
9
9
|
@print_strategy = PrintStrategy::Default
|
10
10
|
@allow_production = false
|
11
11
|
@methods_whitelist = []
|
12
|
+
@methods_blacklist = []
|
12
13
|
end
|
13
14
|
|
14
15
|
def ignore_methods_from
|
15
|
-
|
16
|
+
convert_to_array(@ignore_methods_from)
|
16
17
|
end
|
17
18
|
|
18
|
-
def methods_whitelist
|
19
|
-
|
19
|
+
def methods_whitelist=(methods)
|
20
|
+
raise ::Putter::MethodConflictError unless (@methods_blacklist & methods).empty?
|
21
|
+
|
22
|
+
@methods_whitelist = methods
|
20
23
|
end
|
21
24
|
|
22
|
-
def
|
25
|
+
def methods_blacklist=(methods)
|
26
|
+
raise ::Putter::MethodConflictError unless (@methods_whitelist & methods).empty?
|
27
|
+
|
28
|
+
@methods_blacklist = methods
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def convert_to_array(val)
|
23
34
|
if val.nil?
|
24
35
|
[]
|
25
36
|
elsif !val.is_a?(Array)
|
data/lib/putter/errors.rb
CHANGED
data/lib/putter/follower.rb
CHANGED
@@ -30,7 +30,7 @@ module Putter
|
|
30
30
|
def add_method(method)
|
31
31
|
proxy_method_data = ProxyMethodData.new(label: @data.label, method: method)
|
32
32
|
|
33
|
-
|
33
|
+
add_putter_method_to_proxy(@proxy, proxy_method_data)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
data/lib/putter/follower_data.rb
CHANGED
@@ -5,18 +5,21 @@ module Putter
|
|
5
5
|
def initialize(object, proxy, options)
|
6
6
|
@proxy = proxy
|
7
7
|
@proxied_methods = options[:methods] || []
|
8
|
-
|
8
|
+
set_label(options[:label], object)
|
9
9
|
end
|
10
10
|
|
11
11
|
def add_method?(method)
|
12
12
|
return false if @proxy.instance_methods.include?(method)
|
13
|
-
return true if _is_whitelisted_method?(method)
|
14
|
-
return false if _is_ignored_method?(method)
|
15
|
-
return true if @proxied_methods.empty?
|
16
13
|
return true if @proxied_methods.include?(method)
|
14
|
+
return true if is_whitelisted_method?(method)
|
15
|
+
return false if is_blacklisted_method?(method)
|
16
|
+
return false if is_ignored_method?(method)
|
17
|
+
return true if @proxied_methods.empty?
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
+
private
|
21
|
+
|
22
|
+
def set_label(label, object)
|
20
23
|
if !label.nil?
|
21
24
|
@label = label
|
22
25
|
elsif object.class == Class
|
@@ -26,11 +29,15 @@ module Putter
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
32
|
+
def is_whitelisted_method?(method)
|
30
33
|
::Putter.configuration.methods_whitelist.map(&:to_sym).include?(method.to_sym)
|
31
34
|
end
|
32
35
|
|
33
|
-
def
|
36
|
+
def is_blacklisted_method?(method)
|
37
|
+
::Putter.configuration.methods_blacklist.map(&:to_sym).include?(method.to_sym)
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_ignored_method?(method)
|
34
41
|
::Putter.configuration.ignore_methods_from.each do |klass|
|
35
42
|
return true if klass.methods.include?(method.to_sym)
|
36
43
|
return true if klass.instance_methods.include?(method.to_sym)
|
@@ -1,17 +1,7 @@
|
|
1
1
|
module Putter
|
2
2
|
module MethodCreator
|
3
|
-
def
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def add_putter_class_method_to_proxy(proxy, data)
|
8
|
-
add_putter_method_to_proxy(proxy, data, :module_exec)
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def add_putter_method_to_proxy(proxy, data, eval_method)
|
14
|
-
proxy.send(eval_method, data) do |data|
|
3
|
+
def add_putter_method_to_proxy(proxy, data)
|
4
|
+
proxy.send(:instance_exec, data) do |data|
|
15
5
|
define_method(data.method) do |*proxy_args, &blk|
|
16
6
|
line = caller.find {|call| call.match(data.stack_trace_ignore_regex)}
|
17
7
|
data.line = line.split(::Dir.pwd)[1]
|
data/lib/putter/version.rb
CHANGED
data/lib/putter/watcher.rb
CHANGED
@@ -31,7 +31,7 @@ module Putter
|
|
31
31
|
|
32
32
|
Putter::Watcher.methods_for(klass).each do |method|
|
33
33
|
data = ProxyMethodData.new(label: Putter::Watcher.label_for(klass), method: method)
|
34
|
-
|
34
|
+
add_putter_method_to_proxy(proxy, data)
|
35
35
|
end
|
36
36
|
|
37
37
|
proxy
|
data/lib/putter/watcher_data.rb
CHANGED
@@ -3,11 +3,11 @@ module Putter
|
|
3
3
|
attr_accessor :label, :proxy_methods
|
4
4
|
|
5
5
|
def initialize(options, klass)
|
6
|
-
@label =
|
7
|
-
@proxy_methods =
|
6
|
+
@label = set_label(options[:label], klass)
|
7
|
+
@proxy_methods = set_methods(options[:methods], klass.singleton_class)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def set_label(label, klass)
|
11
11
|
if !label.nil? && label != ""
|
12
12
|
label
|
13
13
|
else
|
@@ -15,9 +15,9 @@ module Putter
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def set_methods(methods, singleton_klass)
|
19
19
|
if methods.nil?
|
20
|
-
|
20
|
+
methods_to_proxy(singleton_klass)
|
21
21
|
elsif !methods.is_a?(Array)
|
22
22
|
[methods]
|
23
23
|
else
|
@@ -25,14 +25,16 @@ module Putter
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
ignored_methods =
|
28
|
+
def methods_to_proxy(singleton_klass)
|
29
|
+
ignored_methods = Putter.configuration.methods_blacklist.map(&:to_sym)
|
30
30
|
|
31
31
|
Putter.configuration.ignore_methods_from.each do |klass|
|
32
32
|
ignored_methods += klass.methods
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
whitelist = Putter.configuration.methods_whitelist.map(&:to_sym) + [:new]
|
36
|
+
|
37
|
+
singleton_klass.instance_methods - ignored_methods + whitelist
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: putter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John DeWyze
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|