betterp 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 58eaa19df226afd2a1c13607d5f0bd2922ba5dbf
4
- data.tar.gz: 11ea87d1d868e5a57290b287213a80af3de9e534
2
+ SHA256:
3
+ metadata.gz: 14eca65c37298f3f7f28bd0ea317eb12fcc739db2e7502a0487addeef5997c90
4
+ data.tar.gz: b6fc5f08ca75600e220cc153593ca0b1bdec8a239e7af9266d4301792ba46484
5
5
  SHA512:
6
- metadata.gz: 9733a777982e76a05dc0eb54a02da495717709afaa0ff2fec42e6232ea9075e94554ea88afa178e3a800c71818bb6ac8a27fb77c11c43a6c27167f8bec42ce88
7
- data.tar.gz: 5ef71acdfcc923dc64ede41d117b1bc91c477210396556122aa0b098b593d41d765e806572279b63fe9c5ad127960f21a8b62b6b25db79031a207984beafd0d4
6
+ metadata.gz: 782f0b93d39771daaa86e13b8655a13aa1ac41c349bef5e04a0e93015ff65475a2561bdf8beda5b03b314804591b8fb75a60b7a1a942940f9aaefaffdcf22431
7
+ data.tar.gz: 509b64a135cc221547a497c1e6f94edf0d5cceb2a9528c0b117b95c482de535a0861b4573211ec475518d2cf4353d07e178829561c5e7cd0707c2c981e2a60e8
data/.gitignore CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Gemfile.lock
10
10
 
11
- # rspec failure tracking
11
+ .ruby-version
12
12
  .rspec_status
13
13
  .byebug_history
14
14
  *.swp
@@ -0,0 +1,18 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/StringLiterals:
5
+ Exclude:
6
+ - 'lib/betterp/output.rb'
7
+
8
+ Style/FormatString:
9
+ Exclude:
10
+ - 'lib/betterp/output.rb'
11
+
12
+ Style/FormatStringToken:
13
+ Exclude:
14
+ - 'lib/betterp/output.rb'
15
+
16
+ AllCops:
17
+ Exclude:
18
+ - 'bin/**/*'
data/Makefile CHANGED
@@ -1,4 +1,5 @@
1
1
  .PHONY: test
2
2
  test:
3
- bundle exec rspec
4
- bundle exec rubocop
3
+ bin/rspec
4
+ bin/rubocop
5
+ bin/strong_versions
data/README.md CHANGED
@@ -1,11 +1,5 @@
1
1
  # betterp
2
2
 
3
- ```
4
- If we can find the light
5
- We'll find the light, come on
6
- --Nickelback
7
- ```
8
-
9
3
  ## Overview
10
4
 
11
5
  _betterp_ emulates _Ruby_'s default `p` with a few extra goodies.
@@ -22,7 +16,7 @@ The original semantics of `Kernel#p` are still applied, i.e. it returns the valu
22
16
  Add the gem to your `Gemfile`
23
17
 
24
18
  ```ruby
25
- gem 'strong_versions', '~> 0.3.0'
19
+ gem 'betterp', '~> 0.1.6'
26
20
  ```
27
21
 
28
22
  And rebuild your bundle:
@@ -31,9 +25,9 @@ And rebuild your bundle:
31
25
  $ bundle install
32
26
  ```
33
27
 
34
- Or install yourself:
28
+ Or install standalone:
35
29
  ```bash
36
- $ gem install strong_versions -v '0.3.0'
30
+ $ gem install betterp -v '0.1.6'
37
31
  ```
38
32
 
39
33
  ## Usage
@@ -6,6 +6,7 @@ require 'betterp/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'betterp'
9
+ spec.licenses = ['MIT']
9
10
  spec.version = Betterp::VERSION
10
11
  spec.authors = ['Bob Farrell']
11
12
  spec.email = ['bob@homeflow.co.uk']
@@ -29,5 +30,6 @@ Gem::Specification.new do |spec|
29
30
  spec.add_development_dependency 'rake', '~> 10.0'
30
31
  spec.add_development_dependency 'rspec', '~> 3.0'
31
32
  spec.add_development_dependency 'rspec-its', '~> 1.2'
32
- spec.add_development_dependency 'rubocop', '~> 0.60.0'
33
+ spec.add_development_dependency 'rubocop', '~> 0.77.0'
34
+ spec.add_development_dependency 'strong_versions', '~> 0.3.2'
33
35
  end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'strong_versions' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("strong_versions", "strong_versions")
Binary file
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'betterp'
2
4
 
3
5
  class MyCustomClass
@@ -6,8 +8,8 @@ end
6
8
  p 'hello'
7
9
  p 'hi'
8
10
  p 'debug output'
9
- p *%w[hello bob how are you]
10
- p({ i: 'am', a: 'hash' })
11
+ p 'hello', 'bob', 'how', 'are', 'you'
12
+ p(i: 'am', a: 'hash')
11
13
  p MyCustomClass.new
12
14
  p 'hello again'
13
15
  p 'etc.'
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'digest'
4
+ require 'pathname'
5
+ require 'pp'
6
+ require 'stringio'
4
7
 
5
8
  require 'paint'
6
9
 
@@ -5,23 +5,64 @@ module Betterp
5
5
  COLORS = %i[red green yellow blue magenta cyan].freeze
6
6
  EFFECTS = [:bright, nil].freeze
7
7
 
8
- def initialize(raw, source)
8
+ def initialize(raw, source, options = {})
9
9
  @raw = raw
10
10
  @source = source
11
11
  @color = color
12
12
  @effect = effect
13
+ @pretty = options.fetch(:pretty, false)
13
14
  end
14
15
 
15
16
  def format(args)
16
- args.map do |arg|
17
- colorize(prefix) + Paint[arg.inspect, :default, :bright]
17
+ (@pretty ? args : args.map(&:inspect)).map do |arg|
18
+ style = %i[yellow]
19
+ header + colorize(prefix) + caller_code + Paint[pretty(arg), *style]
18
20
  end
19
21
  end
20
22
 
21
23
  private
22
24
 
25
+ def pretty(arg)
26
+ return arg unless @pretty
27
+
28
+ io = StringIO.new
29
+ PP.pp(arg, io)
30
+ return io.string unless io.string.include?("\n")
31
+
32
+ "\n" + io.string.split("\n").map { |line| " #{line}" }.join("\n")
33
+ end
34
+
35
+ def caller_code
36
+ return '' unless @raw.include?(':')
37
+
38
+ path, line, *_rest = @raw.split(':')
39
+ return '' unless Pathname.new(path).readable? && line.to_i.positive?
40
+
41
+ Paint % [
42
+ +'%{open}%{code}%{close}',
43
+ :default,
44
+ open: ['{ ', :white, :default],
45
+ code: [find_caller(line.to_i, path).to_s.strip, :cyan],
46
+ close: [' } ', :white, :default]
47
+ ]
48
+ end
49
+
50
+ def find_caller(line_number, path)
51
+ lines = File.readlines(path)
52
+ token = @pretty ? 'pp' : 'p'
53
+ lines[0...line_number].reverse.find { |line| line.match(/\b#{token}\b/) }
54
+ end
55
+
56
+ def header
57
+ Paint % [
58
+ +"%{standard}%{relevant}",
59
+ :default,
60
+ standard: [' ', :default],
61
+ relevant: ['•••• ', @color, @effect]
62
+ ]
63
+ end
64
+
23
65
  def prefix
24
- # rubocop:disable Style/FormatStringToken
25
66
  [
26
67
  '%{path}',
27
68
  '%{separator}',
@@ -30,24 +71,21 @@ module Betterp
30
71
  '%{method_name}',
31
72
  '%{terminator}'
32
73
  ].join
33
- # rubocop:enable Style/FormatStringToken
34
74
  end
35
75
 
36
76
  def colorize(string)
37
- # rubocop:disable Style/FormatString
38
- Paint % [string, color, mapping]
39
- # rubocop:enable Style/FormatString
77
+ Paint % [string, :default, mapping]
40
78
  end
41
79
 
42
80
  def mapping
43
81
  {
44
- path: [@source.path, color, :underline, effect],
45
- line_no: [@source.line_no, :underline, color, effect],
46
- method_name: [@source.method_name, color, effect],
82
+ path: [@source.path],
83
+ line_no: [@source.line_no],
84
+ method_name: [@source.method_name],
47
85
 
48
- method_pointer: [' => ', :default, :reset, :bright],
49
- separator: [':', :default, :reset],
50
- terminator: [' :: ', :default, :reset]
86
+ method_pointer: [' => ', :reset, :bright],
87
+ separator: [':', :reset],
88
+ terminator: [' :: ', :reset]
51
89
  }
52
90
  end
53
91
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Betterp
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.6'
5
5
  end
@@ -3,10 +3,20 @@
3
3
  module Kernel
4
4
  def p(*args)
5
5
  raw = caller(1..1).first
6
+ _betterp(raw, args)
7
+ end
8
+
9
+ def pp(*args)
10
+ raw = caller(1..1).first
11
+ _betterp(raw, args, pretty: true)
12
+ end
13
+
14
+ def _betterp(raw, args, options = {})
6
15
  source = Betterp::Source.new(raw, Dir.pwd)
16
+ pretty = options.fetch(:pretty, false)
7
17
 
8
- Betterp::Output.new(raw, source).format(args).each do |output|
9
- STDOUT.write(output + "\n")
18
+ Betterp::Output.new(raw, source, pretty: pretty).format(args).each do |str|
19
+ STDOUT.write(str + "\n")
10
20
  end
11
21
 
12
22
  args.size > 1 ? args : args.first
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-08 00:00:00.000000000 Z
11
+ date: 2020-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paint
@@ -86,14 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.60.0
89
+ version: 0.77.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.60.0
96
+ version: 0.77.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: strong_versions
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.3.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.3.2
97
111
  description: Replaces Kernel#p with a fancier version
98
112
  email:
99
113
  - bob@homeflow.co.uk
@@ -103,6 +117,7 @@ extra_rdoc_files: []
103
117
  files:
104
118
  - ".gitignore"
105
119
  - ".rspec"
120
+ - ".rubocop.yml"
106
121
  - Gemfile
107
122
  - LICENSE
108
123
  - Makefile
@@ -110,7 +125,10 @@ files:
110
125
  - Rakefile
111
126
  - betterp.gemspec
112
127
  - bin/console
128
+ - bin/rspec
129
+ - bin/rubocop
113
130
  - bin/setup
131
+ - bin/strong_versions
114
132
  - doc/images/screenshot.png
115
133
  - doc/testp.rb
116
134
  - lib/betterp.rb
@@ -119,7 +137,8 @@ files:
119
137
  - lib/betterp/version.rb
120
138
  - lib/kernel.rb
121
139
  homepage: https://github.com/bobf/betterp
122
- licenses: []
140
+ licenses:
141
+ - MIT
123
142
  metadata: {}
124
143
  post_install_message:
125
144
  rdoc_options: []
@@ -136,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
155
  - !ruby/object:Gem::Version
137
156
  version: '0'
138
157
  requirements: []
139
- rubyforge_project:
140
- rubygems_version: 2.5.2.2
158
+ rubygems_version: 3.0.3
141
159
  signing_key:
142
160
  specification_version: 4
143
161
  summary: Enhanced debug output