betterp 0.1.0 → 0.1.1

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
2
  SHA1:
3
- metadata.gz: 55c8d01c5d2b646fe695c25f21fcbf3087256693
4
- data.tar.gz: c41bbb1ac04217b8deb4012d928ef54fb0d19e1c
3
+ metadata.gz: 58eaa19df226afd2a1c13607d5f0bd2922ba5dbf
4
+ data.tar.gz: 11ea87d1d868e5a57290b287213a80af3de9e534
5
5
  SHA512:
6
- metadata.gz: fded6c3023ff132759b372eefc9627e148625fb1276c044ed425ebfc026869dd9d69ffc3a08402ae51200cbb1e76971e488a4e7ca9ee314351f0ffa2ad776929
7
- data.tar.gz: d6d04561089b7d778b8e31d8638b71372352f4636357a81d17cf0a3413718dc95a0ccfa5688f690b6a4b9bcdf2e8b50ec7a04f10966e64df0f231c722d1afb3a
6
+ metadata.gz: 9733a777982e76a05dc0eb54a02da495717709afaa0ff2fec42e6232ea9075e94554ea88afa178e3a800c71818bb6ac8a27fb77c11c43a6c27167f8bec42ce88
7
+ data.tar.gz: 5ef71acdfcc923dc64ede41d117b1bc91c477210396556122aa0b098b593d41d765e806572279b63fe9c5ad127960f21a8b62b6b25db79031a207984beafd0d4
data/.gitignore CHANGED
@@ -2,7 +2,6 @@
2
2
  /.yardoc
3
3
  /_yardoc/
4
4
  /coverage/
5
- /doc/
6
5
  /pkg/
7
6
  /spec/reports/
8
7
  /tmp/
@@ -14,3 +13,4 @@ Gemfile.lock
14
13
  .byebug_history
15
14
  *.swp
16
15
  *.swo
16
+ betterp-*.gem
data/Makefile ADDED
@@ -0,0 +1,4 @@
1
+ .PHONY: test
2
+ test:
3
+ bundle exec rspec
4
+ bundle exec rubocop
data/README.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## Overview
4
10
 
5
11
  _betterp_ emulates _Ruby_'s default `p` with a few extra goodies.
@@ -35,6 +41,8 @@ $ gem install strong_versions -v '0.3.0'
35
41
  Call `p` from anywhere in your code just as you normally would:
36
42
 
37
43
  ```ruby
44
+ require 'betterp'
45
+
38
46
  p 'hello'
39
47
  ```
40
48
 
data/betterp.gemspec CHANGED
@@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'bundler', '~> 1.16'
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
31
32
  spec.add_development_dependency 'rubocop', '~> 0.60.0'
32
33
  end
Binary file
data/doc/testp.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'betterp'
2
+
3
+ class MyCustomClass
4
+ end
5
+
6
+ p 'hello'
7
+ p 'hi'
8
+ p 'debug output'
9
+ p *%w[hello bob how are you]
10
+ p({ i: 'am', a: 'hash' })
11
+ p MyCustomClass.new
12
+ p 'hello again'
13
+ p 'etc.'
14
+
15
+ def foo
16
+ p 'hi from a method'
17
+ end
18
+
19
+ foo
data/lib/betterp.rb CHANGED
@@ -6,7 +6,11 @@ require 'paint'
6
6
 
7
7
  require 'kernel'
8
8
  require 'betterp/output'
9
+ require 'betterp/source'
9
10
  require 'betterp/version'
10
11
 
11
12
  module Betterp
13
+ def self.root
14
+ Pathname.new(File.dirname(__dir__))
15
+ end
12
16
  end
@@ -1,38 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Betterp
2
4
  class Output
3
- COLORS = %i[
4
- red
5
- green
6
- yellow
7
- blue
8
- magenta
9
- cyan
10
- ].freeze
11
-
5
+ COLORS = %i[red green yellow blue magenta cyan].freeze
12
6
  EFFECTS = [:bright, nil].freeze
13
7
 
14
- def initialize(source)
8
+ def initialize(raw, source)
9
+ @raw = raw
15
10
  @source = source
11
+ @color = color
12
+ @effect = effect
16
13
  end
17
14
 
18
15
  def format(args)
19
16
  args.map do |arg|
20
- colorize("#{@source}: ") + arg.inspect
17
+ colorize(prefix) + Paint[arg.inspect, :default, :bright]
21
18
  end
22
19
  end
23
20
 
24
21
  private
25
22
 
23
+ def prefix
24
+ # rubocop:disable Style/FormatStringToken
25
+ [
26
+ '%{path}',
27
+ '%{separator}',
28
+ '%{line_no}',
29
+ '%{method_pointer}',
30
+ '%{method_name}',
31
+ '%{terminator}'
32
+ ].join
33
+ # rubocop:enable Style/FormatStringToken
34
+ end
35
+
26
36
  def colorize(string)
27
- Paint[string, color, effect]
37
+ # rubocop:disable Style/FormatString
38
+ Paint % [string, color, mapping]
39
+ # rubocop:enable Style/FormatString
40
+ end
41
+
42
+ def mapping
43
+ {
44
+ path: [@source.path, color, :underline, effect],
45
+ line_no: [@source.line_no, :underline, color, effect],
46
+ method_name: [@source.method_name, color, effect],
47
+
48
+ method_pointer: [' => ', :default, :reset, :bright],
49
+ separator: [':', :default, :reset],
50
+ terminator: [' :: ', :default, :reset]
51
+ }
28
52
  end
29
53
 
30
54
  def color
31
- COLORS[hash(@source).hex % COLORS.size]
55
+ COLORS[hash(@raw).hex % COLORS.size]
32
56
  end
33
57
 
34
58
  def effect
35
- EFFECTS[hash(hash(@source)).hex % EFFECTS.size]
59
+ EFFECTS[hash(hash(@raw)).hex % EFFECTS.size]
36
60
  end
37
61
 
38
62
  def hash(input)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Betterp
4
+ class Source
5
+ def initialize(source, base_path)
6
+ @source = source
7
+ @base_path = base_path
8
+ @path, @line_no, @method_info = source.split(':')
9
+ end
10
+
11
+ def path
12
+ Pathname.new(@path).relative_path_from(Pathname.new(@base_path)).to_s
13
+ rescue ArgumentError
14
+ @path
15
+ end
16
+
17
+ def line_no
18
+ @line_no.to_i
19
+ end
20
+
21
+ def method_name
22
+ @method_info.partition('`').last.chomp("'")
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Betterp
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/kernel.rb CHANGED
@@ -1,8 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kernel
2
4
  def p(*args)
3
- Betterp::Output.new(caller(1..1).first).format(args).each do |output|
5
+ raw = caller(1..1).first
6
+ source = Betterp::Source.new(raw, Dir.pwd)
7
+
8
+ Betterp::Output.new(raw, source).format(args).each do |output|
4
9
  STDOUT.write(output + "\n")
5
10
  end
11
+
6
12
  args.size > 1 ? args : args.first
7
13
  end
8
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -91,13 +105,17 @@ files:
91
105
  - ".rspec"
92
106
  - Gemfile
93
107
  - LICENSE
108
+ - Makefile
94
109
  - README.md
95
110
  - Rakefile
96
111
  - betterp.gemspec
97
112
  - bin/console
98
113
  - bin/setup
114
+ - doc/images/screenshot.png
115
+ - doc/testp.rb
99
116
  - lib/betterp.rb
100
117
  - lib/betterp/output.rb
118
+ - lib/betterp/source.rb
101
119
  - lib/betterp/version.rb
102
120
  - lib/kernel.rb
103
121
  homepage: https://github.com/bobf/betterp