putter 0.4.1 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 72890e1762d7aad4835c7be72838d2409ecfd101
4
- data.tar.gz: 0e24d52624633980ca47e6f1a2830e037d016a99
2
+ SHA256:
3
+ metadata.gz: 4bb34206f87355ec6413702f263574ba0ea9f45fbf01da9578af7c899d4bbe0d
4
+ data.tar.gz: 444c407875667ffcc61d8be7908faeb0e67cd2fc21c2b87e0db45171dc1ac0ad
5
5
  SHA512:
6
- metadata.gz: a575a07d97f70930a795fdfea66d6c14d4ee27a41eee406206fdde067e71f847576e04065702f2ef4611cc6d52b019c4cf32fccaf2fe18628346895de8c44be0
7
- data.tar.gz: bf1e697ce25b56fd736742b3a15303547249e355c804326a04951c3f36331505b066bbdda01a0097fd01ef248687a16a48ed73c24f272c9def9d2da78a57d865
6
+ metadata.gz: d928358ecf0442f8512988f46f7090e7faade53aea9e14c0419ebe2cf830a666d16bfb67a3ff5d789de9d83a7634464fe57a9134a7739c1451849b0fc257ca67
7
+ data.tar.gz: a2fb566c1bf2b1f99e8f8cb681a97f3968259e6e7e502341ba8dbd32b69ca127eaab24274e502d11e511da4c87270397bddc09cdc9b725c43386f99b8de284ba
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  putter-*.gem
10
+ Gemfile.lock
11
+ vendor/
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.8
1
+ 3.0.2
data/CHANGELOG.md CHANGED
@@ -1,4 +1,17 @@
1
1
  # CHANGELOG
2
+ ### 0.6.1 - 2021-08-02
3
+ - Update required ruby version to at least 2.7
4
+ -
5
+ ### 0.6.0 - 2021-08-02
6
+ - Update required ruby version to 2.7
7
+
8
+ ### 0.5.1 - 2016-11-11
9
+ - Add hotfix for putter running on a script in a local directory to print out the file information
10
+
11
+ ### 0.5.0 - 2016-11-10
12
+ - Add methods blacklist to the configuration options
13
+ - Ensures that local method options override anything in the blacklist
14
+
2
15
  ### 0.4.1 - 2016-10-16
3
16
  - By default, Putter will not run in production mode in Rails, this can be allow via configuration
4
17
  - By default, Putter will ignore methods from ActiveRecord::Base if it is present
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Putter
2
2
 
3
+ ### Still Maintained as of February 2020
4
+
5
+ ## Description
6
+
3
7
  It rhymes with gooder, not gutter.
4
8
 
5
9
  Putter is a tool for more easily implementing puts debugging. Instead of littering files with various puts statements, you can wrap an object with a follower or watcher and print out anytime a method is called on that object. This will follow the object throughout its path in the stack.
@@ -60,8 +64,11 @@ Putter Debugging: Object instance ./putter/README.md:57 -- Method: :hello, Args:
60
64
  ```ruby
61
65
  Putter.follow(
62
66
  object_to_follow,
63
- label: "My object", # Optional - Label to use after "Putter Debugging: My object". Will be "ClassName" for classes or "ClassName instance" for instances
64
- methods: ["my_method"], # Optional - If array is empty, then all methods will be watched. Otherwise, this is an array of methods to print debugging input for
67
+ label: "My object", # Optional - Label to use after "Putter Debugging: My object".
68
+ # Will be "ClassName" for classes or "ClassName instance" for instances
69
+ methods: ["my_method"], # Optional - If array is empty, then all methods will be watched.
70
+ # Otherwise, this is an array of methods to print debugging input for. This will override
71
+ # any settings in the configuration blacklist
65
72
  )
66
73
  ```
67
74
 
@@ -102,7 +109,9 @@ Putter Debugging: MyObject instance 1 ./putter/README.md:97 -- Method: :hello_in
102
109
  Putter.watch(
103
110
  ClassToWatch,
104
111
  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. Otherwise, this is an array of methods to print debugging input for
112
+ methods: ["my_method"], # Optional - If array is empty, then all methods will be watched.
113
+ # Otherwise, this is an array of methods to print debugging input for. This will override
114
+ # any settings in the configuration blacklist
106
115
  )
107
116
  ```
108
117
 
@@ -116,6 +125,7 @@ Putter.configure do |config|
116
125
  # method, args string, and result respectively. This block will be used after each method
117
126
  # is called, it must contain puts or logger calls, to print or any other method callbacks
118
127
  # that are helpful.
128
+
119
129
  # Defaults to Putter::PrintStrategy::Default
120
130
  config.print_strategy = Proc.new do |data|
121
131
  puts "#{data.line} - Label: #{data.label}, Method: #{data.method}, Args: #{data.args}, Result: #{data.result}"
@@ -123,17 +133,26 @@ Putter.configure do |config|
123
133
 
124
134
  # "ignore_methods_from" takes an array of class names and will ignore both class and instance methods
125
135
  # from those classes when adding methods to the proxy and adding debug output
136
+
126
137
  # Defaults to [Object] or [Object, ActiveRecord::Based] if defined
127
138
  config.ignore_methods_from = [Object, ActiveRecord::Base]
128
139
 
129
140
  # "methods_whitelist" takes an array of methods and will always proxy and debug those methods
130
141
  # regardless of whether or not the class is ignored and regardless of what methods are passed
131
142
  # in when running "Putter.follow" or "Putter.watch"
143
+
132
144
  # Defaults to []
133
145
  config.methods_whitelist = [:to_s]
134
146
 
147
+ # "methods_blacklist" takes an array of methods and will never proxy. If this is combined
148
+ # with the `methods_whitelist` then it will raise a `MethodConflictError`.
149
+
150
+ # Defaults to []
151
+ config.methods_blacklist = [:to_s]
152
+
135
153
  # "allow_production" takes a boolean and determines whether or not Putter will run if
136
154
  # `Rails.env == "production"`
155
+
137
156
  # Defaults to false
138
157
  config.allow_production = false
139
158
  end
@@ -1,7 +1,7 @@
1
1
  module Putter
2
2
  class Configuration
3
- attr_accessor :print_strategy, :allow_production
4
- attr_writer :ignore_methods_from, :methods_whitelist
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
- _convert_to_array(@ignore_methods_from)
16
+ convert_to_array(@ignore_methods_from)
16
17
  end
17
18
 
18
- def methods_whitelist
19
- _convert_to_array(@methods_whitelist)
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 _convert_to_array(val)
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
@@ -4,4 +4,10 @@ module Errors
4
4
  super
5
5
  end
6
6
  end
7
+
8
+ class MethodConflictError < StandardError
9
+ def initialize(msg="Methods cannot be white and blacklisted")
10
+ super
11
+ end
12
+ end
7
13
  end
@@ -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
- add_putter_instance_method_to_proxy(@proxy, proxy_method_data)
33
+ add_putter_method_to_proxy(@proxy, proxy_method_data)
34
34
  end
35
35
  end
36
36
  end
@@ -5,18 +5,21 @@ module Putter
5
5
  def initialize(object, proxy, options)
6
6
  @proxy = proxy
7
7
  @proxied_methods = options[:methods] || []
8
- _set_label(options[:label], object)
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
- def _set_label(label, object)
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 _is_whitelisted_method?(method)
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 _is_ignored_method?(method)
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,20 +1,12 @@
1
1
  module Putter
2
2
  module MethodCreator
3
- def add_putter_instance_method_to_proxy(proxy, data)
4
- add_putter_method_to_proxy(proxy, data, :instance_exec)
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
- line = caller.find {|call| call.match(data.stack_trace_ignore_regex)}
17
- data.line = line.split(::Dir.pwd)[1]
6
+ data.line = caller.find {|call| call.match(data.stack_trace_ignore_regex)}
7
+ if data.line.include?(::Dir.pwd)
8
+ data.line = data.line.split(::Dir.pwd)[1]
9
+ end
18
10
  data.args = proxy_args.to_s
19
11
  data.result = super *proxy_args, &blk
20
12
  ::Putter.configuration.print_strategy.call data
@@ -4,7 +4,13 @@ module Putter
4
4
  module PrintStrategy
5
5
  Default = Proc.new do |data|
6
6
  prefix = "\tPutter Debugging: #{data.label} ".colorize(:cyan)
7
- line = !data.line.nil? ? ".#{data.line} " : " "
7
+ if data.line.nil?
8
+ line = " "
9
+ elsif data.line[0] != "/"
10
+ line = "./#{data.line} "
11
+ else
12
+ line = ".#{data.line} "
13
+ end
8
14
  suffix = "-- Method: :#{data.method}, Args: #{data.args}, Result: #{data.result}".colorize(:green)
9
15
  puts prefix + line + suffix
10
16
  end
@@ -1,3 +1,3 @@
1
1
  module Putter
2
- VERSION = "0.4.1"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -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
- add_putter_class_method_to_proxy(proxy, data)
34
+ add_putter_method_to_proxy(proxy, data)
35
35
  end
36
36
 
37
37
  proxy
@@ -3,11 +3,11 @@ module Putter
3
3
  attr_accessor :label, :proxy_methods
4
4
 
5
5
  def initialize(options, klass)
6
- @label = _set_label(options[:label], klass)
7
- @proxy_methods = _set_methods(options[:methods], klass.singleton_class)
6
+ @label = set_label(options[:label], klass)
7
+ @proxy_methods = set_methods(options[:methods], klass.singleton_class)
8
8
  end
9
9
 
10
- def _set_label(label, klass)
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 _set_methods(methods, singleton_klass)
18
+ def set_methods(methods, singleton_klass)
19
19
  if methods.nil?
20
- _methods_to_proxy(singleton_klass)
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 _methods_to_proxy(singleton_klass)
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
- singleton_klass.instance_methods - ignored_methods + Putter.configuration.methods_whitelist.map(&:to_sym) + [:new]
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
data/putter.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/dewyze/putter"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.required_ruby_version = '~> 2.1'
17
+ spec.required_ruby_version = '>= 2.7.0'
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
20
  spec.bindir = "bin"
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_runtime_dependency 'colorize', '~> 0'
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.12"
27
- spec.add_development_dependency "pry", "~> 0.10.3"
28
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "bundler", "~> 2.1"
27
+ spec.add_development_dependency "pry", "~> 0.14.1"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  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.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John DeWyze
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-17 00:00:00.000000000 Z
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.12'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.10.3
47
+ version: 0.14.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.10.3
54
+ version: 0.14.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -99,7 +99,6 @@ files:
99
99
  - CHANGELOG.md
100
100
  - CODE_OF_CONDUCT.md
101
101
  - Gemfile
102
- - Gemfile.lock
103
102
  - LICENSE.txt
104
103
  - README.md
105
104
  - Rakefile
@@ -123,24 +122,23 @@ homepage: https://github.com/dewyze/putter
123
122
  licenses:
124
123
  - MIT
125
124
  metadata: {}
126
- post_install_message:
125
+ post_install_message:
127
126
  rdoc_options: []
128
127
  require_paths:
129
128
  - lib
130
129
  required_ruby_version: !ruby/object:Gem::Requirement
131
130
  requirements:
132
- - - "~>"
131
+ - - ">="
133
132
  - !ruby/object:Gem::Version
134
- version: '2.1'
133
+ version: 2.7.0
135
134
  required_rubygems_version: !ruby/object:Gem::Requirement
136
135
  requirements:
137
136
  - - ">="
138
137
  - !ruby/object:Gem::Version
139
138
  version: '0'
140
139
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.4.8
143
- signing_key:
140
+ rubygems_version: 3.2.22
141
+ signing_key:
144
142
  specification_version: 4
145
143
  summary: Putter makes puts debugging easy.
146
144
  test_files: []
data/Gemfile.lock DELETED
@@ -1,45 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- putter (0.4.1)
5
- colorize (~> 0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- coderay (1.1.1)
11
- colorize (0.7.7)
12
- diff-lcs (1.2.5)
13
- method_source (0.8.2)
14
- pry (0.10.3)
15
- coderay (~> 1.1.0)
16
- method_source (~> 0.8.1)
17
- slop (~> 3.4)
18
- rake (10.5.0)
19
- rspec (3.4.0)
20
- rspec-core (~> 3.4.0)
21
- rspec-expectations (~> 3.4.0)
22
- rspec-mocks (~> 3.4.0)
23
- rspec-core (3.4.4)
24
- rspec-support (~> 3.4.0)
25
- rspec-expectations (3.4.0)
26
- diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.4.0)
28
- rspec-mocks (3.4.1)
29
- diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.4.0)
31
- rspec-support (3.4.1)
32
- slop (3.6.0)
33
-
34
- PLATFORMS
35
- ruby
36
-
37
- DEPENDENCIES
38
- bundler (~> 1.12)
39
- pry (~> 0.10.3)
40
- putter!
41
- rake (~> 10.0)
42
- rspec (~> 3.0)
43
-
44
- BUNDLED WITH
45
- 1.13.5