super_awesome_print 0.2.5 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 34d264ee0c1c98ab9bf51ff823019fb9ae8733a2
4
- data.tar.gz: 5df02c87f4e02beff1b81eb707f81e1401d5e338
2
+ SHA256:
3
+ metadata.gz: 8dcbcd2d03a3005179e357dba79cac9ff235c4ef582aaaeaec9723191f7e6b14
4
+ data.tar.gz: 410e5466d12988d153b738f05381dbf9e920b7e0b0817bf7ec50997fd928f5cd
5
5
  SHA512:
6
- metadata.gz: 54874f1aa1b87400a77c7c05131f23bf203b69961d154bfcf189644e478056bbf0b3ce1228db5d353c7c24b2a5023f5b3b2a2bffe6d051ddba40d7c7cbd90877
7
- data.tar.gz: 68957448dd7b8b0ea25a45f0cc56e051bbffb58acd17ce627f740a2085fc42a60fdef18aa4487604b03af68fa1940c0b877a824bd9aed1afc0b2a195eaac0d63
6
+ metadata.gz: 85a06d0fbe8691681ceab0bf43bcfc58c78dfc98122d2e32240c6a805f8eaea0aa93a9c9a4f043e6f525dad18d39452219b68ab2a657c423c1f42e90358bbf65
7
+ data.tar.gz: '008722bc3e34bb2955a4fb16656067136bcf9967cc9507660bdec2ff068c742cc9b6146fd7f57e226930094ed6cef50fc3f57458251cbfe68e3cfc27d9eed2b6'
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # SuperAwesomePrint
2
2
 
3
- Add colored '*********', time and line number around printed value. It's easier to find such output in a long console output.
3
+ [![CI](https://github.com/olegantonyan/super_awesome_print/actions/workflows/ci.yml/badge.svg)](https://github.com/olegantonyan/super_awesome_print/actions/workflows/ci.yml)
4
+
5
+ Prints values with [awesome_print](https://github.com/awesome-print/awesome_print), framed by colored `***` markers, a timestamp and the caller location, so they're easy to spot in long console output.
6
+
7
+ ![screenshot](https://cloud.githubusercontent.com/assets/2301579/12552398/45e9fa4c-c37a-11e5-8113-a9014d153ebb.png)
4
8
 
5
- ![alt tag](https://cloud.githubusercontent.com/assets/2301579/12552398/45e9fa4c-c37a-11e5-8113-a9014d153ebb.png)
6
9
  ```ruby
7
10
  def index
8
11
  @posts = Post.all
@@ -18,50 +21,58 @@ Add this line to your application's Gemfile:
18
21
  gem 'super_awesome_print'
19
22
  ```
20
23
 
21
- And then execute:
24
+ And then run:
22
25
 
23
26
  $ bundle install
24
27
 
25
- Or install it yourself as:
28
+ Or install it yourself:
26
29
 
27
30
  $ gem install super_awesome_print
28
31
 
29
- You can optionally customize configuration in an initializer.<br/>
30
- In Rails, you can add the following to `config/initializers/super_awesome_print.rb`:
32
+ Requires Ruby 2.7 or newer.
33
+
34
+ ## Configuration
35
+
36
+ Optionally, customize it in an initializer. In Rails, add the following to `config/initializers/super_awesome_print.rb`:
31
37
 
32
38
  ```ruby
33
39
  SuperAwesomePrint.configure do |config|
34
- config.caller_lines = 3 # defaults to 1
40
+ config.caller_lines = 3 # number of backtrace lines to print, defaults to 1
35
41
  config.blank_lines_top = 2 # defaults to 0
36
42
  config.blank_lines_bottom = 2 # defaults to 0
37
- config.root_path = Rails.root.to_s # this path will be removed from caller's files path, defaults to Rails.root.to_s
38
- config.log_file_path = '/some/path/to/log/file' # override default log file for `sapf`
43
+ config.root_path = Rails.root.to_s # stripped from caller paths, defaults to Rails.root
44
+ config.log_file_path = '/some/path/to/log/file' # where `sapf` writes
39
45
  end
40
46
  ```
41
47
 
42
48
  ## Usage
43
49
 
44
- Just use `sap` global function to print any variable.
50
+ Call `sap` anywhere to print a value. It returns its argument, so you can wrap an expression without changing it:
45
51
 
46
- You can also print to a file
52
+ ```ruby
53
+ total = sap(items.sum(&:price))
54
+ ```
55
+
56
+ To write to a file instead, use `sapf`:
47
57
 
48
58
  ```ruby
49
59
  sapf 'hello world'
50
60
  ```
51
61
 
52
- By default it will print everything to `sapf.log` file in current directory or to `log/sapf.log` if you're on Rails. See `log_file_path` config option to override this.
62
+ By default, `sapf` appends to `sapf.log` in the current directory, or to `log/sapf.log` in Rails. Set `log_file_path` to change it.
63
+
64
+ To keep `sap` from leaking into production, see the [RuboCop cop](https://github.com/olegantonyan/super_awesome_print_rubocop).
53
65
 
54
66
  ## Development
55
67
 
56
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+ After checking out the repo, run `bin/setup` to install dependencies, then `bundle exec rake test` to run the tests. Run `bin/console` for an interactive prompt.
57
69
 
58
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, then run `bundle exec rake release`. This creates a git tag for the version, pushes git commits and tags, and pushes the `.gem` file to [rubygems.org](https://rubygems.org).
59
71
 
60
72
  ## Contributing
61
73
 
62
- Bug reports and pull requests are welcome on GitHub at https://github.com/olegantonyan/super_awesome_print. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://www.contributor-covenant.org) code of conduct.
63
-
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/olegantonyan/super_awesome_print. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://www.contributor-covenant.org) code of conduct.
64
75
 
65
76
  ## License
66
77
 
67
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,11 +1,19 @@
1
- class Configuration
2
- attr_accessor :caller_lines, :blank_lines_top, :blank_lines_bottom, :root_path, :log_file_path
1
+ module SuperAwesomePrint
2
+ class Configuration
3
+ attr_accessor :caller_lines, :blank_lines_top, :blank_lines_bottom, :root_path, :log_file_path
3
4
 
4
- def initialize
5
- @caller_lines = 1
6
- @blank_lines_top = 0
7
- @blank_lines_bottom = 0
8
- @root_path = defined?(Rails) ? Rails.root.to_s : ''
9
- @log_file_path = @root_path.empty? ? Dir.pwd + '/sapf.log' : @root_path + '/log/sapf.log'
5
+ def initialize
6
+ @caller_lines = 1
7
+ @blank_lines_top = 0
8
+ @blank_lines_bottom = 0
9
+ @root_path = rails_root
10
+ @log_file_path = @root_path.empty? ? File.join(Dir.pwd, 'sapf.log') : File.join(@root_path, 'log', 'sapf.log')
11
+ end
12
+
13
+ private
14
+
15
+ def rails_root
16
+ defined?(::Rails) && ::Rails.respond_to?(:root) ? ::Rails.root.to_s : ''
17
+ end
10
18
  end
11
19
  end
@@ -1,3 +1,3 @@
1
1
  module SuperAwesomePrint
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.7'.freeze
3
3
  end
@@ -3,33 +3,29 @@ require 'super_awesome_print/configuration'
3
3
  require 'awesome_print'
4
4
 
5
5
  module Kernel
6
+ private
7
+
6
8
  def sap(msg)
7
9
  SuperAwesomePrint.blank_lines_top
8
- ap "*** #{Time.now} ***", :color => { :string => :green }
9
- ap msg.class if msg.respond_to?(:class)
10
- SuperAwesomePrint.print_caller_lines(caller)
10
+ ap "*** #{Time.now} ***", color: { string: :green }
11
+ ap msg.class
12
+ SuperAwesomePrint.trace(caller).each { |line| ap line, color: { string: :purpleish } }
11
13
  ap msg
12
- ap '*** END ***', :color => { :string => :green }
14
+ ap '*** END ***', color: { string: :green }
13
15
  SuperAwesomePrint.blank_lines_bottom
16
+ msg
14
17
  end
15
18
 
16
19
  def sapf(msg)
17
- file = File.open(SuperAwesomePrint.config.log_file_path , 'a')
18
- file.puts("*** #{Time.now} ***")
19
- file.puts(" class: #{msg.class}") if msg.respond_to?(:class)
20
- lines = caller[0...SuperAwesomePrint.config.caller_lines].map do |line|
21
- root_path = SuperAwesomePrint.config.root_path
22
- if root_path.empty?
23
- line
24
- else
25
- line.gsub(root_path + '/', '')
26
- end
20
+ trace = SuperAwesomePrint.trace(caller)
21
+ File.open(SuperAwesomePrint.config.log_file_path, 'a') do |file|
22
+ file.puts("*** #{Time.now} ***")
23
+ file.puts(" class: #{msg.class}")
24
+ trace.each { |line| file.puts(" trace: #{line}") }
25
+ file.puts(msg.inspect)
26
+ file.puts('*** END ***')
27
27
  end
28
- lines.each { |l| file.puts(' trace: ' + l) }
29
- file.puts(msg.inspect)
30
- file.puts('*** END ***')
31
- ensure
32
- file.close
28
+ msg
33
29
  end
34
30
  end
35
31
 
@@ -38,17 +34,16 @@ module SuperAwesomePrint
38
34
  attr_writer :configuration
39
35
  end
40
36
 
41
- def self.print_caller_lines(caller_array)
42
- number_of_lines = config.caller_lines
43
- lines = caller_array[0...number_of_lines].map do |line|
44
- line.gsub(config.root_path + '/', '')
45
- end
46
- lines.each { |line| ap line, :color => { :string => :purpleish } }
37
+ def self.trace(backtrace)
38
+ lines = backtrace.first(config.caller_lines)
39
+ root = config.root_path.to_s.chomp('/')
40
+ return lines if root.empty?
41
+
42
+ lines.map { |line| line.sub(%r{\A#{Regexp.escape(root)}/}, '') }
47
43
  end
48
44
 
49
45
  def self.blank_lines_top
50
- # The first puts has no visible effect
51
- # So we want to puts once regardless of config
46
+ # the first puts has no visible effect, so always print one
52
47
  puts
53
48
  config.blank_lines_top.times { puts }
54
49
  end
@@ -58,7 +53,7 @@ module SuperAwesomePrint
58
53
  end
59
54
 
60
55
  def self.config
61
- SuperAwesomePrint.configuration
56
+ configuration
62
57
  end
63
58
 
64
59
  def self.configuration
metadata CHANGED
@@ -1,84 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_awesome_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Antonyan
8
- autorequire:
9
- bindir: exe
8
+ bindir: bin
10
9
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: awesome_print
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '1.10'
20
- type: :development
18
+ version: '0'
19
+ type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '1.10'
25
+ version: '0'
27
26
  - !ruby/object:Gem::Dependency
28
- name: rake
27
+ name: minitest
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
30
+ - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '10.0'
32
+ version: '0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - "~>"
37
+ - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: '10.0'
39
+ version: '0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: awesome_print
41
+ name: rake
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - ">="
46
45
  - !ruby/object:Gem::Version
47
46
  version: '0'
48
- type: :runtime
47
+ type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- description: Add colored '*********', time and line number around printed value
54
+ description: Prints values with awesome_print, framed by colored markers, a timestamp
55
+ and the caller location.
56
56
  email:
57
57
  - oleg.b.antonyan@gmail.com
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
65
- - CODE_OF_CONDUCT.md
66
- - Gemfile
67
62
  - LICENSE.txt
68
63
  - README.md
69
- - Rakefile
70
- - bin/console
71
- - bin/setup
72
64
  - lib/super_awesome_print.rb
73
65
  - lib/super_awesome_print/configuration.rb
74
66
  - lib/super_awesome_print/version.rb
75
- - sapf.log
76
- - super_awesome_print.gemspec
77
- homepage: http://github.com/olegantonyan/super_awesome_print
67
+ homepage: https://github.com/olegantonyan/super_awesome_print
78
68
  licenses:
79
69
  - MIT
80
70
  metadata: {}
81
- post_install_message:
82
71
  rdoc_options: []
83
72
  require_paths:
84
73
  - lib
@@ -86,16 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
75
  requirements:
87
76
  - - ">="
88
77
  - !ruby/object:Gem::Version
89
- version: '0'
78
+ version: '2.7'
90
79
  required_rubygems_version: !ruby/object:Gem::Requirement
91
80
  requirements:
92
81
  - - ">="
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.2.5
98
- signing_key:
85
+ rubygems_version: 4.0.16
99
86
  specification_version: 4
100
- summary: Simple wrapper around awesome_print for easier look in long log
87
+ summary: awesome_print wrapper that makes debug output easy to spot in long logs
101
88
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.3
4
- before_install: gem install bundler -v 1.10.6
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in super_awesome_print.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'super_awesome_print'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
data/sapf.log DELETED
@@ -1,5 +0,0 @@
1
- *** 2017-03-17 18:40:40 +0200 ***
2
- class: Fixnum
3
- trace: (irb):1:in `irb_binding'
4
- 1
5
- *** END ***
@@ -1,30 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'super_awesome_print/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'super_awesome_print'
8
- spec.version = SuperAwesomePrint::VERSION
9
- spec.authors = ['Oleg Antonyan']
10
- spec.email = ['oleg.b.antonyan@gmail.com']
11
-
12
- spec.summary = 'Simple wrapper around awesome_print for easier look in long log'
13
- spec.description = "Add colored '*********', time and line number around printed value"
14
- spec.homepage = 'http://github.com/olegantonyan/super_awesome_print'
15
- spec.license = 'MIT'
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ['lib']
21
-
22
- spec.add_development_dependency 'bundler', '~> 1.10'
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
-
25
- if RUBY_VERSION < '1.9.3'
26
- spec.add_runtime_dependency 'awesome_print', '1.2.0'
27
- else
28
- spec.add_runtime_dependency 'awesome_print'
29
- end
30
- end