betterp 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Makefile +4 -0
- data/README.md +8 -0
- data/betterp.gemspec +1 -0
- data/doc/images/screenshot.png +0 -0
- data/doc/testp.rb +19 -0
- data/lib/betterp.rb +4 -0
- data/lib/betterp/output.rb +38 -14
- data/lib/betterp/source.rb +25 -0
- data/lib/betterp/version.rb +1 -1
- data/lib/kernel.rb +7 -1
- metadata +19 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 58eaa19df226afd2a1c13607d5f0bd2922ba5dbf
         | 
| 4 | 
            +
              data.tar.gz: 11ea87d1d868e5a57290b287213a80af3de9e534
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9733a777982e76a05dc0eb54a02da495717709afaa0ff2fec42e6232ea9075e94554ea88afa178e3a800c71818bb6ac8a27fb77c11c43a6c27167f8bec42ce88
         | 
| 7 | 
            +
              data.tar.gz: 5ef71acdfcc923dc64ede41d117b1bc91c477210396556122aa0b098b593d41d765e806572279b63fe9c5ad127960f21a8b62b6b25db79031a207984beafd0d4
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/Makefile
    ADDED
    
    
    
        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
    
    
    
        data/lib/betterp/output.rb
    CHANGED
    
    | @@ -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( | 
| 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 | 
            -
                   | 
| 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(@ | 
| 55 | 
            +
                  COLORS[hash(@raw).hex % COLORS.size]
         | 
| 32 56 | 
             
                end
         | 
| 33 57 |  | 
| 34 58 | 
             
                def effect
         | 
| 35 | 
            -
                  EFFECTS[hash(hash(@ | 
| 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
         | 
    
        data/lib/betterp/version.rb
    CHANGED
    
    
    
        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 | 
            -
                 | 
| 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. | 
| 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
         |