puts_debug 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 1b5045d6b353e5ed671ecd5593e5cca502d7c5b8f50a90e9b476b374e557538f
4
- data.tar.gz: 20cdf993397c80391642843b642447b52cc14188609b54ed9b99a8aa7f29e7fb
3
+ metadata.gz: 3356209ac7938c3d9f056c7aa40195ed60f99c79b0fefc44974e74ae0ffe94b7
4
+ data.tar.gz: e46f3e1a03a7db00ef005e8a40e0db34332ebd0fb76019e5d75ed03ad6e601b9
5
5
  SHA512:
6
- metadata.gz: a96703aca8706f660e2ffa8f3accf0b54cf923e79a3048389b9e95426d8c0c407df328ffe0cb36c4e88ff5a2f9100a6dc9e5e8802d4169615e110507a595b9b3
7
- data.tar.gz: df06601eff1b8812d7ef839039bb4ceafd65ba39aee8760c42d3482019980625c1ed487efc3e74f4a0f29f35783a87285caf5f162f418c39f552d362a72f53aa
6
+ metadata.gz: b0f652b644c6ee3181fd37123cead208ff25b32ee175b402feec8382ae6247c29012d882653cc99cfb6c369ef672434b73ce5dc17ffd5d564c2d5e6527d06563
7
+ data.tar.gz: bf4c72e4a614a04df8f52ae781fad2d12d258e24260065e0bb1aee32225ad54af1387239712733ab77687580eb66fd275538ecbe11458f4a17fa3d03d96e2711
data/README.md CHANGED
@@ -41,47 +41,35 @@ then you can
41
41
 
42
42
  # Method signature:
43
43
 
44
- def pd(h = {}, line_symbol = nil, show_lines = :both, empty_lines_margin = nil)
44
+ def pd(args)
45
45
  # ...
46
46
  end
47
47
 
48
48
 
49
- pd('something') # =>
50
- something
51
-
52
- pd({name: 'Yogurt', calories: 200}) # =>
49
+ pd('something') =>
50
+ ============================================================
51
+ something
52
+ ============================================================
53
+
54
+ pd(data: 'something', data_color: 'magenta', lines: :none) =>
55
+ something
56
+
57
+ pd(name: 'Yogurt') =>
58
+ ============================================================
53
59
  name: Yogurt
54
- calories: 200
55
-
56
-
57
- pd(1, '-', :both, 1) #=>
60
+ ============================================================
58
61
 
62
+ pd(data: 1, symbol: '-', margin: 1) =>
63
+
59
64
  ------------------------------------------------------------
60
65
  1
61
66
  ------------------------------------------------------------
62
-
63
- pd({a: 1, b: 3}, '*', :both, 2) #=>
64
-
65
67
 
68
+ pd(data: {a: 1, b: 3}, symbol: '*') =>
66
69
  ************************************************************
67
70
  a: 1
68
71
  b: 3
69
72
  ************************************************************
70
-
71
-
72
- pd({a: 1, b: 3}, '=', :top, 1)
73
- pd('In the midlle')
74
- pd({c:2, d: 33}, '=', :bottom, 1)
75
- #=>
76
-
77
- ============================================================
78
- a: 1
79
- b: 3
80
- In the midlle
81
- c: 2
82
- d: 33
83
- ============================================================
84
-
85
73
  ```
86
74
 
87
75
  ## Development
@@ -1,3 +1,3 @@
1
1
  module PutsDebug
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/puts_debug.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require "puts_debug/version"
2
2
 
3
3
  module Kernel
4
-
5
4
  ##
6
5
  # For easier puts debugging (pd). Defined in Kernel module which is included into Object class so this method
7
6
  # is accessible from everywhere. Output is sent to standard error stream (stderr) so it could be further separated
@@ -18,44 +17,92 @@ module Kernel
18
17
  # Examples:
19
18
  #
20
19
  # pd('something') =>
20
+ # ============================================================
21
+ # something
22
+ # ============================================================
23
+ #
24
+ # pd(data: 'something', data_color: 'magenta', lines: :none) =>
21
25
  # something
22
26
  #
23
27
  # pd(name: 'Yogurt') =>
28
+ # ============================================================
24
29
  # name: Yogurt
30
+ # ============================================================
25
31
  #
26
- # pd(1, '-', :both, 1) =>
32
+ # pd(data: 1, symbol: '-', margin: 1) =>
27
33
  #
28
34
  # ------------------------------------------------------------
29
35
  # 1
30
36
  # ------------------------------------------------------------
31
37
  #
32
- # pd({a: 1, b: 3}, '*', :both, 2) =>
33
- #
34
- #
38
+ # pd(data: {a: 1, b: 3}, symbol: '*') =>
35
39
  # ************************************************************
36
40
  # a: 1
37
41
  # b: 3
38
42
  # ************************************************************
39
- #
40
- #
41
- def pd(h = {}, line_symbol = nil, show_lines = :both, empty_lines_margin = nil)
43
+ def pd(args)
44
+ params = nil
45
+
46
+ if args.is_a? Hash
47
+ if args[:data].nil?
48
+ params = { data: args }
49
+ else
50
+ params = args
51
+ end
52
+ else
53
+ params = { data: args }
54
+ end
55
+
56
+ # parameters
57
+ data = params[:data]
58
+ symbol = params[:symbol] || '='
59
+ line_color = params[:color] || 'red'
60
+ data_color = params[:data_color] || nil
61
+ margin = params[:margin] || 0
62
+ lines = params[:lines] || :both
63
+ title = params[:title]
64
+ epilogue = params[:epilogue]
42
65
 
43
- return unless Rails.env.development?
66
+ # locals
67
+ line_str = Rainbow(symbol * 60).try(line_color)
68
+ margin_str = "\n" * margin
44
69
 
45
- $stderr.puts "\n" * empty_lines_margin if empty_lines_margin.present? && show_lines.in?([:both, :top])
46
- $stderr.puts (line_symbol * 60) if line_symbol.present? && show_lines.in?([:both, :top])
70
+ $stderr.puts margin_str if margin > 0 && lines.in?([:both, :top])
71
+ $stderr.puts line_str if lines.in?([:both, :top])
47
72
 
48
- if h.is_a? Hash
49
- h.each do |k, v|
50
- $stderr.puts "#{k}: #{v}"
73
+ if title.present?
74
+ title_str = if title.ends_with? ':'
75
+ "#{title}\n"
76
+ else
77
+ "#{title}:\n"
51
78
  end
79
+
80
+ $stderr.puts Rainbow(title_str).try(line_color)
81
+ end
82
+
83
+ data_str = case data
84
+ when Hash
85
+ data.map { |k, v| "#{k}: #{v}" }.join("\n")
86
+ when Array
87
+ data.map { |v| "#{v}" }.join(",\n")
52
88
  else
53
- $stderr.puts h
89
+ data.to_s
54
90
  end
55
91
 
56
- $stderr.puts line_symbol * 60 if line_symbol.present? && show_lines.in?([:both, :bottom])
57
- $stderr.puts "\n" * empty_lines_margin if empty_lines_margin.present? && show_lines.in?([:both, :bottom])
92
+ data_str = Rainbow(data_str).try(data_color) if data_color.present?
58
93
 
94
+ $stderr.puts data_str
95
+
96
+ if title.present?
97
+ $stderr.puts ''
98
+ end
99
+
100
+ $stderr.puts Rainbow(epilogue).try(line_color) if epilogue.present?
101
+
102
+ if lines.present?
103
+ $stderr.puts line_str if lines.in?([:both, :bottom])
104
+ $stderr.puts margin_str if margin > 0 && lines.in?([:both, :bottom])
105
+ end
59
106
  end
60
107
 
61
108
  end
data/puts_debug.gemspec CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
+ spec.add_dependency 'rainbow', '~> 3' # Gem for colorizing printed text on ANSI terminals
28
+
27
29
  spec.add_development_dependency "bundler", "~> 1.16"
28
30
  spec.add_development_dependency "rake", "~> 10.0"
29
31
  spec.add_development_dependency "minitest", "~> 5.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puts_debug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleh Novosad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-01 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement