betterp 0.1.2 → 0.1.3

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: ede79516da0652f02b85606bc9ba0ad436a08fc2
4
- data.tar.gz: b5e74b88668472fe64850a3d7f1d2371b78f6554
2
+ SHA256:
3
+ metadata.gz: 77fbb36e55d0c863d7451219b231702f1520ea7abfd97997863be1da860b9a3f
4
+ data.tar.gz: 234ade8966e9e3e61b88d70e4143915bc842e814abdab13e5bcecb44970024cc
5
5
  SHA512:
6
- metadata.gz: 3613c1f03a649f804a62a53591222b9705c98d6a5ac7b3a551dc4ba591ef0a31ba6b6d341b960b88d78e24d1f5e17e8c0f0c6ce32c56ab9b3fe122404fa8905c
7
- data.tar.gz: 2e7d82ae3d46978d104f2bc92b6c61b19198f9fb60d1737ef8905b2fc33c346f7db2241e85e79258b1e347710d24705d7a661560fa445794ce0ac7053136121d
6
+ metadata.gz: 843988be19cc12f78344cd6392ea98ea636acef8e70f71a12dbb2193ced6fed064dc4ca8fba8a220f420368135c262883fe0faa2285bfcf5e3996cce0e83a2ef
7
+ data.tar.gz: e16a4d415911c0ae530e3aaae83bcfacabaddc2a8a9de5d28ac003f576094458f70377be7903632f337bfc62597baa3b1299b234a0de453f4d78987a463ec4a0
@@ -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
@@ -22,7 +22,7 @@ The original semantics of `Kernel#p` are still applied, i.e. it returns the valu
22
22
  Add the gem to your `Gemfile`
23
23
 
24
24
  ```ruby
25
- gem 'betterp', '~> 0.1.1'
25
+ gem 'betterp', '~> 0.1.2'
26
26
  ```
27
27
 
28
28
  And rebuild your bundle:
@@ -33,7 +33,7 @@ $ bundle install
33
33
 
34
34
  Or install standalone:
35
35
  ```bash
36
- $ gem install betterp -v '0.1.1'
36
+ $ gem install betterp -v '0.1.2'
37
37
  ```
38
38
 
39
39
  ## Usage
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
32
  spec.add_development_dependency 'rspec-its', '~> 1.2'
33
33
  spec.add_development_dependency 'rubocop', '~> 0.60.0'
34
+ spec.add_development_dependency 'strong_versions', '~> 0.3.2'
34
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")
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'digest'
4
+ require 'pathname'
5
+ require 'pp'
4
6
 
5
7
  require 'paint'
6
8
 
@@ -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
17
  args.map do |arg|
17
- colorize(prefix) + Paint[arg.inspect, :default, :bright]
18
+ style = %i[cyan black]
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, :blue, :black],
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,20 +71,17 @@ 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, :reset, color, effect],
82
+ path: [@source.path],
83
+ line_no: [@source.line_no],
84
+ method_name: [@source.method_name],
47
85
 
48
86
  method_pointer: [' => ', :reset, :bright],
49
87
  separator: [':', :reset],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Betterp
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
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.2
4
+ version: 0.1.3
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: 2019-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paint
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.60.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
@@ -138,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
156
  version: '0'
139
157
  requirements: []
140
158
  rubyforge_project:
141
- rubygems_version: 2.5.2.2
159
+ rubygems_version: 2.7.6
142
160
  signing_key:
143
161
  specification_version: 4
144
162
  summary: Enhanced debug output