super_awesome_print 0.2.6 → 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
2
  SHA256:
3
- metadata.gz: e89420aaef1029a21847fffeb95477b60723a8db6e7761b808de8b5ee9e78974
4
- data.tar.gz: 2c6637522c60f7782f51f41162b22f639296dfde4b13eaf2831449100b9fee72
3
+ metadata.gz: 8dcbcd2d03a3005179e357dba79cac9ff235c4ef582aaaeaec9723191f7e6b14
4
+ data.tar.gz: 410e5466d12988d153b738f05381dbf9e920b7e0b0817bf7ec50997fd928f5cd
5
5
  SHA512:
6
- metadata.gz: e4d7e795ac179d1b9c0d289b8690e00e5df00c36cac5db18e7071c96dd7c3b2d801924d401f903f8b3973021a4fba00a562a354f966e198203d460a29fa85d31
7
- data.tar.gz: 676fb0021bff46767b692551a18aaaa88183c5740bcd9b75649e54544385c4097a4d9a067ef2ee022500f4919daf148b8dc28bd07866c5d029d06e49878a27ee
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,52 +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.
53
63
 
54
- Also, take a look at [cop for RuboCop](https://github.com/olegantonyan/super_awesome_print_rubocop) to make `sap` didn't leak into production.
64
+ To keep `sap` from leaking into production, see the [RuboCop cop](https://github.com/olegantonyan/super_awesome_print_rubocop).
55
65
 
56
66
  ## Development
57
67
 
58
- 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.
59
69
 
60
- 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).
61
71
 
62
72
  ## Contributing
63
73
 
64
- 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.
65
-
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.
66
75
 
67
76
  ## License
68
77
 
69
- 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.6'.freeze
2
+ VERSION = '0.2.7'.freeze
3
3
  end
@@ -3,34 +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
14
16
  msg
15
17
  end
16
18
 
17
19
  def sapf(msg)
18
- file = File.open(SuperAwesomePrint.config.log_file_path , 'a')
19
- file.puts("*** #{Time.now} ***")
20
- file.puts(" class: #{msg.class}") if msg.respond_to?(:class)
21
- lines = caller[0...SuperAwesomePrint.config.caller_lines].map do |line|
22
- root_path = SuperAwesomePrint.config.root_path
23
- if root_path.empty?
24
- line
25
- else
26
- line.gsub(root_path + '/', '')
27
- 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 ***')
28
27
  end
29
- lines.each { |l| file.puts(' trace: ' + l) }
30
- file.puts(msg.inspect)
31
- file.puts('*** END ***')
32
- ensure
33
- file.close
28
+ msg
34
29
  end
35
30
  end
36
31
 
@@ -39,17 +34,16 @@ module SuperAwesomePrint
39
34
  attr_writer :configuration
40
35
  end
41
36
 
42
- def self.print_caller_lines(caller_array)
43
- number_of_lines = config.caller_lines
44
- lines = caller_array[0...number_of_lines].map do |line|
45
- line.gsub(config.root_path + '/', '')
46
- end
47
- 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)}/}, '') }
48
43
  end
49
44
 
50
45
  def self.blank_lines_top
51
- # The first puts has no visible effect
52
- # So we want to puts once regardless of config
46
+ # the first puts has no visible effect, so always print one
53
47
  puts
54
48
  config.blank_lines_top.times { puts }
55
49
  end
@@ -59,7 +53,7 @@ module SuperAwesomePrint
59
53
  end
60
54
 
61
55
  def self.config
62
- SuperAwesomePrint.configuration
56
+ configuration
63
57
  end
64
58
 
65
59
  def self.configuration
metadata CHANGED
@@ -1,23 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_awesome_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
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: 2022-07-26 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
18
  version: '0'
20
- type: :development
19
+ type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
@@ -25,7 +24,7 @@ dependencies:
25
24
  - !ruby/object:Gem::Version
26
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
  - - ">="
@@ -39,45 +38,36 @@ dependencies:
39
38
  - !ruby/object:Gem::Version
40
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
- - super_awesome_print.gemspec
76
- homepage: http://github.com/olegantonyan/super_awesome_print
67
+ homepage: https://github.com/olegantonyan/super_awesome_print
77
68
  licenses:
78
69
  - MIT
79
70
  metadata: {}
80
- post_install_message:
81
71
  rdoc_options: []
82
72
  require_paths:
83
73
  - lib
@@ -85,15 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
75
  requirements:
86
76
  - - ">="
87
77
  - !ruby/object:Gem::Version
88
- version: '0'
78
+ version: '2.7'
89
79
  required_rubygems_version: !ruby/object:Gem::Requirement
90
80
  requirements:
91
81
  - - ">="
92
82
  - !ruby/object:Gem::Version
93
83
  version: '0'
94
84
  requirements: []
95
- rubygems_version: 3.3.7
96
- signing_key:
85
+ rubygems_version: 4.0.16
97
86
  specification_version: 4
98
- 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
99
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
@@ -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'
23
- spec.add_development_dependency 'rake'
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