putter 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +2 -2
- data/README.md +19 -19
- data/lib/putter/configuration.rb +23 -4
- data/lib/putter/errors.rb +7 -0
- data/lib/putter/follower.rb +24 -10
- data/lib/putter/print_strategy.rb +4 -10
- data/lib/putter/version.rb +1 -1
- data/lib/putter.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a525258dc08f4793f38bc5d023fc01efda81ba8
|
4
|
+
data.tar.gz: 61e872b2ec792cb1557608f3f329b92123b8fe03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04d82a6530661ed0cbada01906a726195e6e910941b8ae2770c1eb019069f4c1ddb4faa0d80d29052e5db1776fa95720ccb69898e2c8fcc4dd989824d3d7b1ac
|
7
|
+
data.tar.gz: 56152fdd9dd89ae120d75c74d7ceea04e6aef5cbbd46a5b149c85a858bd8e09be0a7d0f566c656c3fcaa3908c5429db9f95ba3577ee4de645d3a92c22f1513b5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
### 0.2.0 - 2016-06-04
|
4
|
+
- Convert print strategies to a single print strategy for both methods calls and results and adjust configuration accordingly.
|
5
|
+
|
6
|
+
### 0.1.1 - 2016-05-29
|
7
|
+
- Fix print strategy to put new line before debugging statements to not have a break between method calls and results.
|
8
|
+
|
9
|
+
### 0.1.0 - 2016-05-29
|
10
|
+
- Initial commit, see README.
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -35,7 +35,7 @@ This code of conduct applies both within project spaces and in public spaces
|
|
35
35
|
when an individual is representing the project or its community.
|
36
36
|
|
37
37
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at
|
38
|
+
reported by contacting a project maintainer at putter@dewyze.io. All
|
39
39
|
complaints will be reviewed and investigated and will result in a response that
|
40
40
|
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
41
|
obligated to maintain confidentiality with regard to the reporter of an
|
@@ -46,4 +46,4 @@ version 1.3.0, available at
|
|
46
46
|
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
47
|
|
48
48
|
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/README.md
CHANGED
@@ -48,11 +48,7 @@ Service.do_stuff(object)
|
|
48
48
|
Will output:
|
49
49
|
|
50
50
|
```bash
|
51
|
-
Putter Debugging:
|
52
|
-
-----------------
|
53
|
-
Method: :value
|
54
|
-
Args: [:world, "!"]
|
55
|
-
Result: "Hello world!"
|
51
|
+
Putter Debugging: Object instance -- Method: :value, Args: [:world, "!"], Result: "Hello world!"
|
56
52
|
```
|
57
53
|
|
58
54
|
#### `Putter.follow` Options
|
@@ -60,8 +56,8 @@ Putter Debugging: Object instance
|
|
60
56
|
```ruby
|
61
57
|
Putter.follow(
|
62
58
|
object_to_follow,
|
63
|
-
label: "My object" # Label to use after "Putter Debugging: My object". Will be "ClassName" for classes or "ClassName instance" for instances
|
64
|
-
methods: ["value"] # If the value is nil, then all methods will be watched. Otherwise, this is an array of methods to print debugging input for
|
59
|
+
label: "My object", # Label to use after "Putter Debugging: My object". Will be "ClassName" for classes or "ClassName instance" for instances
|
60
|
+
methods: ["value"], # If the value is nil, then all methods will be watched. Otherwise, this is an array of methods to print debugging input for
|
65
61
|
)
|
66
62
|
```
|
67
63
|
|
@@ -71,17 +67,23 @@ Putter currently has 3 configuration options:
|
|
71
67
|
|
72
68
|
```ruby
|
73
69
|
Putter.configure do |config|
|
74
|
-
# 'method_strategy' takes a block that receives
|
75
|
-
#
|
76
|
-
|
70
|
+
# 'method_strategy' takes a block that receives four arguments with the label, method, args array,
|
71
|
+
# and result respectively. This block will be used after each method is called, it must contain
|
72
|
+
# puts or logger calls, to print or any other method callbacks that are helpful.
|
73
|
+
# Defaults to Putter::PrintStrategy::Default
|
74
|
+
config.print_strategy = Proc.new do |label, method, args, result|
|
75
|
+
puts "Label: #{label}, Method: #{method}, Args: #{args}, Result: #{result}"
|
76
|
+
end
|
77
77
|
|
78
|
-
# '
|
79
|
-
#
|
80
|
-
|
78
|
+
# 'ignore_methods_from' takes an array of class names and will ignore both class and instance methods
|
79
|
+
# from those classes when adding methods to the proxy and adding debug output
|
80
|
+
# Defaults to [Object]
|
81
|
+
config.ignore_methods_from = [Object, ActiveRecord::Base]
|
81
82
|
|
82
|
-
# '
|
83
|
-
#
|
84
|
-
|
83
|
+
# 'methods_whitelist' takes an array of methods and will always proxy and debug those methods
|
84
|
+
# regardless of whether or not the class is ignored and regardless of what methods are passed
|
85
|
+
# in when running 'Putter.follow'
|
86
|
+
config.methods_whitelist = [:to_s]
|
85
87
|
end
|
86
88
|
```
|
87
89
|
|
@@ -90,13 +92,11 @@ Feel free to open a PR to implement any of these if they are not yet added:
|
|
90
92
|
|
91
93
|
- Ability to watch any instance of a class calling a method
|
92
94
|
- Active Record specific printing
|
93
|
-
- Errors for when attempting to follow a `BasicObject`
|
94
|
-
- Protected methods (so things like `inspect` don't cause stack level too deep errors
|
95
95
|
- Checking Rails.env to double check that putter is not called in production
|
96
96
|
|
97
97
|
## Contributing
|
98
98
|
|
99
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
99
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dewyze/putter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
100
100
|
|
101
101
|
## License
|
102
102
|
|
data/lib/putter/configuration.rb
CHANGED
@@ -1,11 +1,30 @@
|
|
1
1
|
module Putter
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :print_strategy
|
4
|
+
attr_writer :ignore_methods_from, :methods_whitelist
|
4
5
|
|
5
6
|
def initialize
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
7
|
+
@ignore_methods_from = [Object]
|
8
|
+
@print_strategy = PrintStrategy::Default
|
9
|
+
@methods_whitelist = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def ignore_methods_from
|
13
|
+
_convert_to_array(@ignore_methods_from)
|
14
|
+
end
|
15
|
+
|
16
|
+
def methods_whitelist
|
17
|
+
_convert_to_array(@methods_whitelist)
|
18
|
+
end
|
19
|
+
|
20
|
+
def _convert_to_array(val)
|
21
|
+
if val.nil?
|
22
|
+
[]
|
23
|
+
elsif !val.is_a?(Array)
|
24
|
+
[val]
|
25
|
+
else
|
26
|
+
val
|
27
|
+
end
|
9
28
|
end
|
10
29
|
end
|
11
30
|
end
|
data/lib/putter/follower.rb
CHANGED
@@ -5,7 +5,11 @@ module Putter
|
|
5
5
|
def initialize(obj, options={})
|
6
6
|
@object = obj
|
7
7
|
@proxy = MethodProxy.new
|
8
|
-
|
8
|
+
begin
|
9
|
+
@object.singleton_class.send(:prepend, proxy)
|
10
|
+
rescue ::NoMethodError
|
11
|
+
::Kernel.raise ::Putter::BasicObjectError
|
12
|
+
end
|
9
13
|
_set_options(options)
|
10
14
|
end
|
11
15
|
|
@@ -22,19 +26,33 @@ module Putter
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def add_method(method)
|
25
|
-
@proxy.instance_exec(@label
|
29
|
+
@proxy.instance_exec(@label) do |label, print_results|
|
26
30
|
define_method(method) do |*proxy_args, &blk|
|
27
|
-
|
31
|
+
args_string = proxy_args.to_s
|
28
32
|
result = super *proxy_args, &blk
|
29
|
-
::Putter.configuration.
|
33
|
+
::Putter.configuration.print_strategy.call label, method, args_string, result
|
30
34
|
result
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
35
39
|
def _add_method?(method)
|
36
|
-
return
|
37
|
-
|
40
|
+
return true if _is_whitelisted_method?(method)
|
41
|
+
return false if _is_ignored_method?(method)
|
42
|
+
return false if @proxy.instance_methods.include?(method)
|
43
|
+
return @proxy_all_methods || proxied_methods.include?(method.to_s)
|
44
|
+
end
|
45
|
+
|
46
|
+
def _is_ignored_method?(method)
|
47
|
+
::Putter.configuration.ignore_methods_from.each do |klass|
|
48
|
+
return true if klass.methods.include?(method.to_sym)
|
49
|
+
return true if klass.instance_methods.include?(method.to_sym)
|
50
|
+
end
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
54
|
+
def _is_whitelisted_method?(method)
|
55
|
+
::Putter.configuration.methods_whitelist.map(&:to_sym).include?(method.to_sym)
|
38
56
|
end
|
39
57
|
|
40
58
|
def _set_label(label)
|
@@ -47,10 +65,6 @@ module Putter
|
|
47
65
|
end
|
48
66
|
end
|
49
67
|
|
50
|
-
def _print_results?
|
51
|
-
::Putter.configuration.print_results
|
52
|
-
end
|
53
|
-
|
54
68
|
def _set_methods(methods)
|
55
69
|
if methods.nil?
|
56
70
|
@proxy_all_methods = true
|
@@ -2,16 +2,10 @@ require "colorize"
|
|
2
2
|
|
3
3
|
module Putter
|
4
4
|
module PrintStrategy
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
puts
|
9
|
-
puts "\t\t Method: ".colorize(:cyan) + ":#{method}".colorize(:green)
|
10
|
-
puts "\t\t Args: ".colorize(:cyan) + "#{args}".colorize(:green)
|
11
|
-
end
|
12
|
-
|
13
|
-
ResultStrategy = Proc.new do |result|
|
14
|
-
puts "\t\t Result: ".colorize(:cyan) + "#{result}".colorize(:green)
|
5
|
+
Default = Proc.new do |label, method, args, result|
|
6
|
+
prefix = "\tPutter Debugging: ".colorize(:cyan)
|
7
|
+
suffix = "#{label} -- Method: :#{method}, Args: #{args}, Result: #{result}".colorize(:green)
|
8
|
+
puts prefix + suffix
|
15
9
|
end
|
16
10
|
end
|
17
11
|
end
|
data/lib/putter/version.rb
CHANGED
data/lib/putter.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require "putter/configuration"
|
2
|
+
require "putter/errors"
|
2
3
|
require "putter/follower"
|
3
4
|
require "putter/method_proxy"
|
4
5
|
require "putter/print_strategy"
|
5
6
|
require "putter/version"
|
6
7
|
|
7
8
|
module Putter
|
9
|
+
include Errors
|
10
|
+
|
8
11
|
class << self
|
9
12
|
attr_writer :configuration
|
10
13
|
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.2.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-
|
11
|
+
date: 2016-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- ".ruby-gemset"
|
97
97
|
- ".ruby-version"
|
98
98
|
- ".travis.yml"
|
99
|
+
- CHANGELOG.md
|
99
100
|
- CODE_OF_CONDUCT.md
|
100
101
|
- Gemfile
|
101
102
|
- Gemfile.lock
|
@@ -106,6 +107,7 @@ files:
|
|
106
107
|
- bin/setup
|
107
108
|
- lib/putter.rb
|
108
109
|
- lib/putter/configuration.rb
|
110
|
+
- lib/putter/errors.rb
|
109
111
|
- lib/putter/follower.rb
|
110
112
|
- lib/putter/method_proxy.rb
|
111
113
|
- lib/putter/print_strategy.rb
|