betterp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55c8d01c5d2b646fe695c25f21fcbf3087256693
4
+ data.tar.gz: c41bbb1ac04217b8deb4012d928ef54fb0d19e1c
5
+ SHA512:
6
+ metadata.gz: fded6c3023ff132759b372eefc9627e148625fb1276c044ed425ebfc026869dd9d69ffc3a08402ae51200cbb1e76971e488a4e7ca9ee314351f0ffa2ad776929
7
+ data.tar.gz: d6d04561089b7d778b8e31d8638b71372352f4636357a81d17cf0a3413718dc95a0ccfa5688f690b6a4b9bcdf2e8b50ec7a04f10966e64df0f231c722d1afb3a
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+ .byebug_history
15
+ *.swp
16
+ *.swo
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in betterp.gemspec
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2018 Robert Farrell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # betterp
2
+
3
+ ## Overview
4
+
5
+ _betterp_ emulates _Ruby_'s default `p` with a few extra goodies.
6
+
7
+ The standard `Kernel#p` method is overwritten with a version that provides the following features:
8
+
9
+ * All output is prefixed with the file and line number that made the call to `p`
10
+ * The output prefix is colourised. The colour is selected using a hash of the file path and line number so the colours are stable between each run.
11
+
12
+ The original semantics of `Kernel#p` are still applied, i.e. it returns the value(s) passed to it and the result of `#inspect` on each argument is output to a separate line.
13
+
14
+ ## Installation
15
+
16
+ Add the gem to your `Gemfile`
17
+
18
+ ```ruby
19
+ gem 'strong_versions', '~> 0.3.0'
20
+ ```
21
+
22
+ And rebuild your bundle:
23
+
24
+ ```bash
25
+ $ bundle install
26
+ ```
27
+
28
+ Or install yourself:
29
+ ```bash
30
+ $ gem install strong_versions -v '0.3.0'
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Call `p` from anywhere in your code just as you normally would:
36
+
37
+ ```ruby
38
+ p 'hello'
39
+ ```
40
+
41
+ ![betterp](doc/images/screenshot.png)
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bobf/betterp
46
+
47
+ ## License
48
+
49
+ [MIT License](LICENSE)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'betterp/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'betterp'
9
+ spec.version = Betterp::VERSION
10
+ spec.authors = ['Bob Farrell']
11
+ spec.email = ['bob@homeflow.co.uk']
12
+
13
+ spec.summary = 'Enhanced debug output'
14
+ spec.description = 'Replaces Kernel#p with a fancier version'
15
+ spec.homepage = 'https://github.com/bobf/betterp'
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ end
22
+ spec.bindir = 'bin'
23
+ spec.executables = []
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_runtime_dependency 'paint', '~> 2.0'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.60.0'
32
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'betterp'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ require 'paint'
6
+
7
+ require 'kernel'
8
+ require 'betterp/output'
9
+ require 'betterp/version'
10
+
11
+ module Betterp
12
+ end
@@ -0,0 +1,42 @@
1
+ module Betterp
2
+ class Output
3
+ COLORS = %i[
4
+ red
5
+ green
6
+ yellow
7
+ blue
8
+ magenta
9
+ cyan
10
+ ].freeze
11
+
12
+ EFFECTS = [:bright, nil].freeze
13
+
14
+ def initialize(source)
15
+ @source = source
16
+ end
17
+
18
+ def format(args)
19
+ args.map do |arg|
20
+ colorize("#{@source}: ") + arg.inspect
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def colorize(string)
27
+ Paint[string, color, effect]
28
+ end
29
+
30
+ def color
31
+ COLORS[hash(@source).hex % COLORS.size]
32
+ end
33
+
34
+ def effect
35
+ EFFECTS[hash(hash(@source)).hex % EFFECTS.size]
36
+ end
37
+
38
+ def hash(input)
39
+ Digest::MD5.hexdigest(input)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Betterp
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,8 @@
1
+ module Kernel
2
+ def p(*args)
3
+ Betterp::Output.new(caller(1..1).first).format(args).each do |output|
4
+ STDOUT.write(output + "\n")
5
+ end
6
+ args.size > 1 ? args : args.first
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: betterp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bob Farrell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.60.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.60.0
83
+ description: Replaces Kernel#p with a fancier version
84
+ email:
85
+ - bob@homeflow.co.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - betterp.gemspec
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/betterp.rb
100
+ - lib/betterp/output.rb
101
+ - lib/betterp/version.rb
102
+ - lib/kernel.rb
103
+ homepage: https://github.com/bobf/betterp
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.2.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Enhanced debug output
126
+ test_files: []