putter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f928a1b2e12bba00884974d440d4fec3b6bca2ea
4
+ data.tar.gz: c66cd8bf87b7e5366a7fdfc53707c8cb2c330ab8
5
+ SHA512:
6
+ metadata.gz: acf21e52a6333edb6e04d165c05fc5da9576666a03b987d77fa0d5cb23496cdf4fc0447ad1b56cbd50805f94ff89ba4207554756ce737b0a90905cebc6598a53
7
+ data.tar.gz: f09d6ef04b68101be677cb7e978ea9c2deeb1ae76a86e763f7c4b12416dc4576e48ed6a62843cb4b0645cd50c221d364041fc30325118e046ac2b6b60e66ec52
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ putter-*.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require "spec_helper"
2
+ --order rand
3
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ putter
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.8
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.4
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at john.dewyze@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in putter.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ putter (0.0.1)
5
+ colorize
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.12.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 John DeWyze
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Putter
2
+
3
+ It rhymes with gooder, not gutter.
4
+
5
+ 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 and print out anytime a method is called on that object. This will follow the object throughout its path in the stack.
6
+
7
+ For now Putter can only follow a specific the speficic object that it wraps. It currently does not watch a class to see what objects were passed to it unless that specific instance of the class is passed through the stack.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'putter'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install putter
24
+
25
+ ## Usage
26
+
27
+ ### Putter.follow
28
+
29
+ Currently there is only one use for Putter, the `follow` method.
30
+
31
+ ```ruby
32
+ class MyObject
33
+ def hello(arg, punc)
34
+ "Hello #{arg.to_s}#{punc}"
35
+ end
36
+ end
37
+
38
+ module Service
39
+ def self.do_stuff(obj)
40
+ obj.hello(:world, "!")
41
+ end
42
+ end
43
+
44
+ object = Putter.follow(MyObject.new)
45
+ Service.do_stuff(object)
46
+ ```
47
+
48
+ Will output:
49
+
50
+ ```bash
51
+ Putter Debugging: Object instance
52
+ -----------------
53
+ Method: :value
54
+ Args: [:world, "!"]
55
+ Result: "Hello world!"
56
+ ```
57
+
58
+ #### `Putter.follow` Options
59
+
60
+ ```ruby
61
+ Putter.follow(
62
+ 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
65
+ )
66
+ ```
67
+
68
+ ## Configuration
69
+
70
+ Putter currently has 3 configuration options:
71
+
72
+ ```ruby
73
+ Putter.configure do |config|
74
+ # 'method_strategy' takes a block that receives three arguments with the label, method, and args array, respectively. This block will be used after each method is called, "puts" statements can be used, or any other method callbacks that are helpful.
75
+ # Defaults to Putter::PrintStrategy::MethodStrategy
76
+ config.method_strategy = Proc.new {|label, method, args| puts "Label: #{label}, Method: #{method}, Args: #{args}" }
77
+
78
+ # 'result_strategy' takes a block that receives a single argument outputs the results of the method call
79
+ # Defaults to Putter::PrintStrategy::ResultStrategy
80
+ config.result_strategy = Proc.new {|result| puts "The result was #{result}" }
81
+
82
+ # 'print_results' determines whether or not to print the results block at all.
83
+ # Defaults to true.
84
+ config.print_results = false
85
+ end
86
+ ```
87
+
88
+ ## Planned Features
89
+ Feel free to open a PR to implement any of these if they are not yet added:
90
+
91
+ - Ability to watch any instance of a class calling a method
92
+ - 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
+ - Checking Rails.env to double check that putter is not called in production
96
+
97
+ ## Contributing
98
+
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "putter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ module Putter
2
+ class Configuration
3
+ attr_accessor :method_strategy, :print_results, :result_strategy
4
+
5
+ def initialize
6
+ @method_strategy = PrintStrategy::MethodStrategy
7
+ @result_strategy = PrintStrategy::ResultStrategy
8
+ @print_results = true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,68 @@
1
+ module Putter
2
+ class Follower < BasicObject
3
+ attr_reader :object, :proxied_methods, :proxy
4
+
5
+ def initialize(obj, options={})
6
+ @object = obj
7
+ @proxy = MethodProxy.new
8
+ @object.singleton_class.send(:prepend, proxy)
9
+ _set_options(options)
10
+ end
11
+
12
+ def method_missing(method, *args, &blk)
13
+ if _add_method?(method)
14
+ add_method(method)
15
+ end
16
+
17
+ if blk
18
+ @object.send(method, *args, &blk)
19
+ else
20
+ @object.send(method, *args)
21
+ end
22
+ end
23
+
24
+ def add_method(method)
25
+ @proxy.instance_exec(@label, _print_results?) do |label, print_results|
26
+ define_method(method) do |*proxy_args, &blk|
27
+ ::Putter.configuration.method_strategy.call label, method, proxy_args
28
+ result = super *proxy_args, &blk
29
+ ::Putter.configuration.result_strategy.call result if print_results
30
+ result
31
+ end
32
+ end
33
+ end
34
+
35
+ def _add_method?(method)
36
+ return (@proxy_all_methods || proxied_methods.include?(method.to_s)) &&
37
+ !@proxy.instance_methods.include?(method)
38
+ end
39
+
40
+ def _set_label(label)
41
+ if !label.nil?
42
+ @label = label
43
+ elsif @object.class == ::Class
44
+ @label = @object.name
45
+ else
46
+ @label = @object.class.name + " instance"
47
+ end
48
+ end
49
+
50
+ def _print_results?
51
+ ::Putter.configuration.print_results
52
+ end
53
+
54
+ def _set_methods(methods)
55
+ if methods.nil?
56
+ @proxy_all_methods = true
57
+ else
58
+ @proxied_methods = methods.map(&:to_s)
59
+ @proxy_all_methods = false
60
+ end
61
+ end
62
+
63
+ def _set_options(options)
64
+ _set_label(options[:label])
65
+ _set_methods(options[:methods])
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,4 @@
1
+ module Putter
2
+ class MethodProxy < Module
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ require "colorize"
2
+
3
+ module Putter
4
+ module PrintStrategy
5
+ MethodStrategy = Proc.new do |label, method, args|
6
+ puts "\tPutter Debugging: ".colorize(:cyan) + "#{label}".colorize(:green)
7
+ puts "\t-----------------".colorize(:cyan)
8
+ puts "\t\t Method: ".colorize(:cyan) + ":#{method}".colorize(:green)
9
+ puts "\t\t Args: ".colorize(:cyan) + "#{args}".colorize(:green)
10
+ puts
11
+ end
12
+
13
+ ResultStrategy = Proc.new do |result|
14
+ puts "\t\t Result: ".colorize(:cyan) + "#{result}".colorize(:green)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Putter
2
+ VERSION = "0.1.0"
3
+ end
data/lib/putter.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "putter/configuration"
2
+ require "putter/follower"
3
+ require "putter/method_proxy"
4
+ require "putter/print_strategy"
5
+ require "putter/version"
6
+
7
+ module Putter
8
+ class << self
9
+ attr_writer :configuration
10
+ end
11
+
12
+ def self.follow(obj, options={})
13
+ Putter::Follower.new(obj, options)
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.configure
21
+ yield configuration
22
+ end
23
+
24
+ def self.reset_configuration
25
+ @configuration = Configuration.new
26
+ end
27
+ end
data/putter.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'putter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "putter"
8
+ spec.version = Putter::VERSION
9
+ spec.authors = ["John DeWyze"]
10
+ spec.email = ["john.dewyze@gmail.com"]
11
+
12
+ spec.description = "Putter provides a variety of methods to easily use puts debugging. It can reveal what methods are called, the arguments that were passed in, and what the result of the method call."
13
+ spec.summary = "Putter makes puts debugging easy."
14
+ spec.homepage = "https://github.com/dewyze/putter"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = '~> 2.1'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency 'colorize', '~> 0'
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"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: putter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John DeWyze
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Putter provides a variety of methods to easily use puts debugging. It
84
+ can reveal what methods are called, the arguments that were passed in, and what
85
+ the result of the method call.
86
+ email:
87
+ - john.dewyze@gmail.com
88
+ executables:
89
+ - console
90
+ - setup
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - ".rspec"
96
+ - ".ruby-gemset"
97
+ - ".ruby-version"
98
+ - ".travis.yml"
99
+ - CODE_OF_CONDUCT.md
100
+ - Gemfile
101
+ - Gemfile.lock
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - bin/console
106
+ - bin/setup
107
+ - lib/putter.rb
108
+ - lib/putter/configuration.rb
109
+ - lib/putter/follower.rb
110
+ - lib/putter/method_proxy.rb
111
+ - lib/putter/print_strategy.rb
112
+ - lib/putter/version.rb
113
+ - putter.gemspec
114
+ homepage: https://github.com/dewyze/putter
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '2.1'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.8
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Putter makes puts debugging easy.
138
+ test_files: []