wrapped_print 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b2b462407500f5c9bc47f7da2768d980beb29957efd2bf57dc390e61317bf71b
4
+ data.tar.gz: 3e12747f68ba6071fc766ddfd85c4419edbaed6aa4c1ef6567accdeee1a39c67
5
+ SHA512:
6
+ metadata.gz: 43fccb41a34c859b6533faa3c33bb3c8a1febdebee3fdfcfcfa36b499571da8ea2abe6133d5d063d481d99c390590f090ea9b0ee814b3af7e3426a40c5908bb1
7
+ data.tar.gz: 027da432b75fd2e26b7c3673d28334645094bf1368f55ca881a0f03faabe40c5d0623bd4497f645cbb1cb2c38dad952a33ed7f38eddebb82d465c6be06cf4513
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wrapped_print.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+
9
+ gem 'activesupport'
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wrapped_print (0.1.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.3.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ concurrent-ruby (1.1.9)
17
+ diff-lcs (1.4.4)
18
+ i18n (1.8.10)
19
+ concurrent-ruby (~> 1.0)
20
+ minitest (5.14.4)
21
+ rake (12.3.3)
22
+ rspec (3.10.0)
23
+ rspec-core (~> 3.10.0)
24
+ rspec-expectations (~> 3.10.0)
25
+ rspec-mocks (~> 3.10.0)
26
+ rspec-core (3.10.1)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-expectations (3.10.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-mocks (3.10.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-support (3.10.2)
35
+ tzinfo (2.0.4)
36
+ concurrent-ruby (~> 1.0)
37
+ zeitwerk (2.4.2)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ activesupport
44
+ rake (~> 12.0)
45
+ rspec (~> 3.0)
46
+ wrapped_print!
47
+
48
+ BUNDLED WITH
49
+ 2.1.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Igor Kasyanchuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # WrappedPrint
2
+
3
+ How usually you debug your code? Binding.pry, byebug, puts, ...
4
+
5
+ How ofter do you write a code something like:
6
+
7
+ ```ruby
8
+ puts "="*50
9
+ puts current_user.full_name
10
+ puts "="*50
11
+ ```
12
+
13
+ I do this at least few times per week, sometimes per day.
14
+
15
+ This is annoying. It's need to be automated. And this gem is a simple solution.
16
+
17
+ Just add this gem and use a global method `.wp` to see in the console value of your object or wrap code in block with `wp { ... }`.
18
+
19
+ See screenshot below with examples of usage (gem can be used not only in specs, this is just an example).
20
+
21
+ [<img src="https://raw.githubusercontent.com/igorkasyanchuk/wrapped_print/main/docs/demo_print.png"
22
+ />](https://raw.githubusercontent.com/igorkasyanchuk/wrapped_print/main/docs/demo_print.png)
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'wrapped_print'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle install
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install wrapped_print
39
+
40
+ And then `require "wrapped_print"`
41
+
42
+ ## Usage
43
+
44
+ You can do a simple configuration to the gem:
45
+
46
+ ```ruby
47
+ WrappedPrint.setup do |config|
48
+ # config.log_to = :console # simply puts
49
+ config.log_to = :logs # e.g. Rails.logger.info....
50
+
51
+ # # applicable only for Logger (not console)
52
+ config.level = :debug
53
+ # config.level = :info
54
+ end
55
+ ```
56
+
57
+ You can print using `puts` or to `Rails.logger`.
58
+
59
+ Output could be customized with several options:
60
+
61
+ ```ruby
62
+ wp(label = nil, pattern: "-", count: 80, prefix: nil, suffix: nil, color: nil)
63
+ ```
64
+
65
+ For example:
66
+
67
+ ```ruby
68
+ "Demo with color 3".wp("COLORIZED: ", color: :pur, pattern: '*')
69
+ ```
70
+
71
+ or
72
+
73
+ ```ruby
74
+ #
75
+ # see how .wp is called. This method `.wp` returning the original value, so you can use it as normal variable.
76
+ #
77
+ class A
78
+ def calc
79
+ z = balance.wp # same as z = balance
80
+ 100 + 200 + z
81
+ end
82
+
83
+ def balance
84
+ 500
85
+ end
86
+ end
87
+ ```
88
+
89
+ ## Development
90
+
91
+ 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.
92
+
93
+ 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).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/igorkasyanchuk/wrapped_print.
98
+
99
+
100
+ ## License
101
+
102
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
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 ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wrapped_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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,78 @@
1
+ require "wrapped_print/version"
2
+ require "active_support"
3
+
4
+ # WrappedPrint.setup do |config|
5
+ # config.log_to = :console # simply puts
6
+ # config.log_to = :logs # e.g. Rails.logger.info....
7
+
8
+ # # applicable only for Logger (not console)
9
+ # config.level = :debug
10
+ # config.level = :info
11
+ # end
12
+
13
+ module WrappedPrint
14
+ mattr_accessor :log_to
15
+ @@log_to = :console
16
+
17
+ mattr_accessor :level
18
+ @@level = :debug
19
+
20
+ def self.setup
21
+ yield(self)
22
+ end
23
+
24
+ module Main
25
+ COLORS = [:none, :red, :green, :dark_blue, :dark_green, :yellow, :blue, :pur]
26
+ PATTERN = "-"
27
+ COUNT = 80
28
+
29
+ def wp(label = nil, pattern: PATTERN, count: COUNT, prefix: nil, suffix: nil, color: nil)
30
+ line = pattern * count
31
+ color_method = detect_color_method(color)
32
+ logger_method = detect_logger_method
33
+
34
+ if block_given?
35
+ result = yield
36
+ result.tap do
37
+ logger_method.call color_method.call "#{prefix}#{line}"
38
+ logger_method.call color_method.call "#{label}#{result}"
39
+ logger_method.call color_method.call "#{line}#{suffix}"
40
+ end
41
+ else
42
+ self.tap do
43
+ logger_method.call color_method.call "#{prefix}#{line}"
44
+ logger_method.call color_method.call "#{label}#{self}"
45
+ logger_method.call color_method.call "#{line}#{suffix}"
46
+ end
47
+ end
48
+ end
49
+
50
+ alias :__wp__ :wp
51
+
52
+ private
53
+ def detect_logger_method
54
+ if WrappedPrint.log_to == :logs
55
+ Rails.logger.method(WrappedPrint.level)
56
+ else
57
+ method(:puts)
58
+ end
59
+ end
60
+
61
+ def detect_color_method(e)
62
+ raise "Unknown color: #{e}. Only #{COLORS} are available." if e && !COLORS.include?(e.to_sym)
63
+ method(e || :none)
64
+ end
65
+
66
+ def none(text); text; end
67
+ def red(text); colorize(text, "\e[1m\e[31m"); end
68
+ def green(text); colorize(text, "\e[1m\e[32m"); end
69
+ def dark_green(text); colorize(text, "\e[32m"); end
70
+ def yellow(text); colorize(text, "\e[1m\e[33m"); end
71
+ def blue(text); colorize(text, "\e[1m\e[34m"); end
72
+ def dark_blue(text); colorize(text, "\e[34m"); end
73
+ def pur(text); colorize(text, "\e[1m\e[35m"); end
74
+ def colorize(text, color_code) "#{color_code}#{text}\e[0m" end
75
+ end
76
+ end
77
+
78
+ Object.send :include, WrappedPrint::Main
@@ -0,0 +1,3 @@
1
+ module WrappedPrint
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/wrapped_print/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "wrapped_print"
5
+ spec.version = WrappedPrint::VERSION
6
+ spec.authors = ["Igor Kasyanchuk"]
7
+ spec.email = ["igorkasyanchuk@gmail.com"]
8
+
9
+ spec.summary = %q{Very simple utility to help your with debugging code and print values to console}
10
+ spec.description = %q{Very simple utility to help your with debugging code and print values to console}
11
+ spec.homepage = "https://github.com/igorkasyanchuk/wrapped_print"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "activesupport"
25
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wrapped_print
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor Kasyanchuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Very simple utility to help your with debugging code and print values
28
+ to console
29
+ email:
30
+ - igorkasyanchuk@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - docs/demo_print.png
46
+ - lib/wrapped_print.rb
47
+ - lib/wrapped_print/version.rb
48
+ - wrapped_print.gemspec
49
+ homepage: https://github.com/igorkasyanchuk/wrapped_print
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/igorkasyanchuk/wrapped_print
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.0.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Very simple utility to help your with debugging code and print values to
73
+ console
74
+ test_files: []