ectoplasm 1.2.3 → 1.4.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: b230ff4690f41e1e3f4d5a474adaa97f1160c35b2b2c492eb096b1e0f787d8f0
4
- data.tar.gz: 3d3734fef7909506527a45c6fe62afb03b6072557d3d2461484341f2f20099b8
3
+ metadata.gz: b1630a2531a6f313b0784aa55fd2fa28df0b6445719d307ec51db1c12f8bd4c2
4
+ data.tar.gz: a562e611642e7a54b116db6e1269b64fc6c5a674b7fbdad0ae9de0381cfb225b
5
5
  SHA512:
6
- metadata.gz: 163dab80bab2fcb6538e7d0055f32649d8d4a5be44b3df0099ab7a28b220d11e343b143cc4016f93705b5f0ccd5b072ab20c3ba3a298a05a1916140a022ad689
7
- data.tar.gz: 1ce583df511099699f66f45da3921818e36d8d7bb37d28bbbbade9f120f47410a8b168e3800b9d0338e6f3d19ab4721b27716c78af8e247e150b3bd35b4c6ff9
6
+ metadata.gz: ea685cded5068288055c2b83c7f0fbbea3e139aa455eff83dfaa2f1dbe2b23f2df77ea4e23cd6e3d6e5d6f26eddca0af066048ec067e8fcfff904d9f639f0c96
7
+ data.tar.gz: 15976b94b9fcce27ef02c2c40d8cc3a380b984f4550d6dc68909d59acc543672f4b071f0c9a553ac2e478d4208fa4b9ff80191b0f74a249d8b24ada84ee99b3e
data/lib/ectoplasm.rb CHANGED
@@ -1,246 +1,239 @@
1
- require 'ostruct'
2
-
3
- module Ectoplasm
4
- module Version
5
- MAJOR = 1
6
- MINOR = 2
7
- TINY = 3
8
- end
9
-
10
- VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
11
-
12
- DEFAULT_SECURE_KEYS = ['password', 'secret', 'token', 'secure', 'pass', 'cert', 'key']
13
-
14
- class ::String
15
- @@colored = false
16
-
17
- def self.colored!
18
- @@colored = true
19
- end
20
-
21
- def white; self; end
22
- def red; colored '31'; end
23
- def green; colored '32'; end
24
- def yellow; colored '33'; end
25
- def blue; colored '34'; end
26
- def magenta; colored '35'; end
27
- def cyan; colored '36'; end
28
- def grey; colored '90'; end
29
-
30
- alias ok green
31
- alias error red
32
- alias warn yellow
33
- alias info blue
34
- alias dim grey
35
-
36
- def indent amount, char: ' '
37
- self.split("\n").map { |line| char * amount + line }.join "\n"
38
- end
39
-
40
- def length
41
- m = /\e\[\d{2}m(.*)\e\[0m/.match self
42
- return self.chars.count - 9 if m
43
- self.chars.count
44
- end
45
-
46
- def frmt props, prefix_suffix=['<', '>']
47
- str = self
48
-
49
- props.keys.each do |key|
50
- placeholder = prefix_suffix[0] + key.to_s + prefix_suffix[1]
51
- str = str.gsub(placeholder, props[key])
52
- end
53
-
54
- str
55
- end
56
-
57
- private
58
-
59
- def colored ansi_color
60
- return self if !@@colored
61
- "\e[#{ansi_color}m#{self}\e[0m"
62
- end
63
- end
64
-
65
-
66
- class ::Object
67
- def pretty width: nil
68
- self.to_s
69
- end
70
-
71
- def obfuscate! secure_keys
72
- self
73
- end
74
- end
75
-
76
-
77
- class ::TrueClass
78
- def pretty width: nil
79
- 'yes'.green
80
- end
81
- end
82
-
83
-
84
- class ::FalseClass
85
- def pretty width: nil
86
- 'no'.yellow
87
- end
88
- end
89
-
90
-
91
- class ::NilClass
92
- def pretty width: nil
93
- 'n/a'.grey
94
- end
95
- end
96
-
97
-
98
- class ::Array
99
- def pretty width: 25
100
- return 'empty'.grey if self.length == 0
101
-
102
- list_length = self.map { |x| x.to_s.length }.reduce(:+)
103
- return self.join ', ' if list_length && list_length < 30
104
-
105
- self
106
- .select { |x| x != nil && x != '' }
107
- .map do |x|
108
- ' - ' + x.pretty(width: width-3).strip.gsub(/\n/, "\n ")
109
- end
110
- .join "\n"
111
- end
112
-
113
- def table header: nil, mappings: {}, with_index: false, limit: 50
114
- header = self[0].keys if header == nil
115
- heading = header.is_a?(Array) ? header : self[0].keys
116
-
117
- table_data = self.slice(0, limit).map do |row|
118
- heading.map do |key|
119
- mappings.has_key?(key) ? mappings[key][row, row[key]] : row[key]
120
- end
121
- end
122
-
123
- table_data.insert(0, heading) if header != false
124
-
125
- data_sizes = table_data.map do |row|
126
- row.map { |data| data.to_s.length }
127
- end
128
-
129
- column_sizes = data_sizes[0]
130
- .zip(*data_sizes[1..-1])
131
- .map { |row| row.max }
132
-
133
- table = table_data.map { |row| column_sizes.zip row }
134
-
135
- table_str = ''
136
- table.each_with_index do |row, index|
137
- if with_index
138
- if index == 0
139
- table_str += ' '
140
- else
141
- table_str += "[#{index}] "
142
- end
143
- end
144
-
145
- row.each do |col_size, data|
146
- table_str += (data.to_s + ' ' * (col_size - data.to_s.length)) + ' '
147
- end
148
-
149
- table_str += "\n"
150
- end
151
- table_str += '[...]' if self.count > limit
152
- print table_str
153
- end
154
-
155
- def obfuscate! secure_keys = DEFAULT_SECURE_KEYS
156
- self.map { |x| x.obfuscate!(secure_keys) }
157
- end
158
- end
159
-
160
-
161
- class ::Hash
162
- def pretty indent: 0, width: 25
163
- s = ''
164
-
165
- self
166
- .select { |key, value| value != nil || value != '' }
167
- .map do |key, value|
168
- value = true if value == 'true'
169
- value = false if value == 'false'
170
- value = '********' if /password|pwd|pass|passwd|secret/ =~ key.to_s
171
-
172
- if value.is_a? Hash
173
- s += key.to_s.cyan.indent(indent) + "\n"
174
- s += value.pretty(width: width-indent-2).indent(indent+2)
175
- s += "\n"
176
- next
177
- end
178
-
179
- s += ' ' * indent
180
-
181
- if value.is_a? Array
182
- list = value.pretty(width: width)
183
-
184
- if list.split("\n").count > 1
185
- s += key.to_s.cyan + "\n"
186
- s += value.pretty(width: width).indent(indent)
187
- s += "\n"
188
- next
189
- end
190
-
191
- value = list
192
- end
193
-
194
- s += key.to_s.cyan
195
- s += ' ' + '.' * (width-key.to_s.length-indent) if width-key.to_s.length > indent
196
- s += ': '
197
- s += value.pretty + "\n"
198
- end
199
-
200
- s
201
- end
202
-
203
- def obfuscate! secure_keys = DEFAULT_SECURE_KEYS
204
- self.each do |k, v|
205
- if v.is_a? Hash
206
- v.obfuscate!(secure_keys)
207
- elsif v.is_a? Array
208
- v.each { |x| v.obfuscate!(secure_keys) }
209
- elsif secure_keys.any? { |x| k.to_s.downcase.include? x.downcase }
210
- self[k] = '*****'
211
- end
212
- end
213
- end
214
- end
215
-
216
-
217
- class ::OpenStruct
218
- def obfuscate! secure_keys = DEFAULT_SECURE_KEYS
219
- OpenStruct.new(self.to_h.obfuscate! secure_keys)
220
- end
221
- end
222
-
223
-
224
- class ::Float
225
- def duration
226
- seconds = self
227
-
228
- if seconds > 60
229
- seconds = seconds.to_i
230
- minutes = seconds / 60
231
- seconds = seconds % 60
232
- end
233
-
234
- if minutes && minutes > 60
235
- hours = minutes / 60
236
- minutes = minutes % 60
237
- end
238
-
239
- duration_str = "#{seconds}s"
240
- duration_str = "#{minutes}m #{duration_str}" if minutes
241
- duration_str = "#{hours}h #{duration_str}" if hours
242
-
243
- duration_str
244
- end
245
- end
246
- end
1
+ require 'ostruct'
2
+
3
+ module Ectoplasm
4
+ module Version
5
+ MAJOR = 1
6
+ MINOR = 4
7
+ TINY = 0
8
+ end
9
+
10
+ VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
11
+
12
+ DEFAULT_SECURE_KEYS = ['password', 'secret', 'token', 'secure', 'pass', 'cert', 'key', 'auth']
13
+
14
+ class ::String
15
+ def white; self; end
16
+ def red; colored '31'; end
17
+ def green; colored '32'; end
18
+ def yellow; colored '33'; end
19
+ def blue; colored '34'; end
20
+ def magenta; colored '35'; end
21
+ def cyan; colored '36'; end
22
+ def grey; colored '90'; end
23
+
24
+ def bold; colored '1'; end
25
+ def underline; colored '4'; end
26
+
27
+ alias ok green
28
+ alias error red
29
+ alias warn yellow
30
+ alias info blue
31
+ alias dim grey
32
+
33
+ def indent amount, char: ' '
34
+ self.split("\n").map { |line| char * amount + line }.join "\n"
35
+ end
36
+
37
+ def length
38
+ m = /\e\[\d{2}m(.*)\e\[0m/.match self
39
+
40
+ return self.chars.count - 9 if m
41
+
42
+ self.chars.count
43
+ end
44
+
45
+ def frmt props, prefix_suffix=['<', '>']
46
+ str = self
47
+
48
+ props.keys.each do |key|
49
+ placeholder = prefix_suffix[0] + key.to_s + prefix_suffix[1]
50
+ str = str.gsub(placeholder, props[key])
51
+ end
52
+
53
+ str
54
+ end
55
+
56
+ private
57
+
58
+ def colored ansi_color
59
+ return self unless $stdout.tty?
60
+
61
+ "\e[#{ansi_color}m#{self}\e[0m"
62
+ end
63
+ end
64
+
65
+ class ::Object
66
+ def pretty(*)
67
+ self.to_s
68
+ end
69
+
70
+ def obfuscate! _secure_keys = nil
71
+ self
72
+ end
73
+ end
74
+
75
+ class ::TrueClass
76
+ def pretty(*)
77
+ 'yes'.green
78
+ end
79
+ end
80
+
81
+ class ::FalseClass
82
+ def pretty(*)
83
+ 'no'.yellow
84
+ end
85
+ end
86
+
87
+ class ::NilClass
88
+ def pretty(*)
89
+ 'n/a'.grey
90
+ end
91
+ end
92
+
93
+ class ::Array
94
+ def pretty width: 25
95
+ return 'empty'.grey if self.empty?
96
+ return self.first.pretty if self.count == 1 and not self.first.is_a? Hash
97
+
98
+ list_length = self.map { |x| x.to_s.length }.reduce(:+)
99
+ return self.join ', ' if list_length && list_length < 30
100
+
101
+ self
102
+ .select { |x| x != nil && x != '' }
103
+ .map do |x|
104
+ ' - ' + x.pretty(width: width-3).strip.gsub(/\n/, "\n ")
105
+ end
106
+ .join "\n"
107
+ end
108
+
109
+ def table header: nil, mappings: {}, with_index: false, limit: 50
110
+ header = self[0].keys if header == nil
111
+ heading = header.is_a?(Array) ? header : self[0].keys
112
+
113
+ table_data = self.slice(0, limit).map do |row|
114
+ heading.map do |key|
115
+ mappings.key?(key) ? mappings[key][row, row[key]] : row[key]
116
+ end
117
+ end
118
+
119
+ table_data.insert(0, heading) if header != false
120
+
121
+ data_sizes = table_data.map do |row|
122
+ row.map { |data| data.to_s.length }
123
+ end
124
+
125
+ column_sizes = data_sizes[0]
126
+ .zip(*data_sizes[1..-1])
127
+ .map { |row| row.max }
128
+
129
+ table = table_data.map { |row| column_sizes.zip row }
130
+
131
+ table_str = ''
132
+ table.each_with_index do |row, index|
133
+ if with_index
134
+ if index == 0
135
+ table_str += ' '
136
+ else
137
+ table_str += "[#{index}] "
138
+ end
139
+ end
140
+
141
+ row.each do |col_size, data|
142
+ table_str += (data.to_s + ' ' * (col_size - data.to_s.length)) + ' '
143
+ end
144
+
145
+ table_str += "\n"
146
+ end
147
+ table_str += '[...]' if self.count > limit
148
+ print table_str
149
+ end
150
+
151
+ def obfuscate! secure_keys = DEFAULT_SECURE_KEYS
152
+ self.map { |x| x.obfuscate!(secure_keys) }
153
+ end
154
+ end
155
+
156
+ class ::Hash
157
+ def pretty indent: 0, width: 25
158
+ s = ''
159
+
160
+ self
161
+ .select { |_, value| value != nil || value != '' }
162
+ .map do |key, value|
163
+ value = true if value == 'true'
164
+ value = false if value == 'false'
165
+ value = '********' if Regexp.new(DEFAULT_SECURE_KEYS.join '|') =~ key.to_s
166
+
167
+ if value.is_a? Hash
168
+ s += key.to_s.cyan.indent(indent) + "\n"
169
+ s += value.pretty(width: width-indent-2).indent(indent+2)
170
+ s += "\n"
171
+ next
172
+ end
173
+
174
+ s += ' ' * indent
175
+
176
+ if value.is_a? Array
177
+ list = value.pretty(width: width)
178
+
179
+ if list.split("\n").count > 1
180
+ s += key.to_s.cyan + "\n"
181
+ s += value.pretty(width: width).indent(indent)
182
+ s += "\n"
183
+ next
184
+ end
185
+
186
+ value = list
187
+ end
188
+
189
+ s += key.to_s.cyan
190
+ s += ' ' + '.' * (width-key.to_s.length-indent) if width-key.to_s.length > indent
191
+ s += ': '
192
+ s += value.pretty + "\n"
193
+ end
194
+
195
+ s
196
+ end
197
+
198
+ def obfuscate! secure_keys = DEFAULT_SECURE_KEYS
199
+ self.each do |k, v|
200
+ if v.is_a? Hash
201
+ v.obfuscate!(secure_keys)
202
+ elsif v.is_a? Array
203
+ v.each { |_| v.obfuscate!(secure_keys) }
204
+ elsif secure_keys.any? { |x| k.to_s.downcase.include? x.downcase }
205
+ self[k] = '*****'
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+ class ::OpenStruct
212
+ def obfuscate! secure_keys = DEFAULT_SECURE_KEYS
213
+ OpenStruct.new(self.to_h.obfuscate! secure_keys)
214
+ end
215
+ end
216
+
217
+ class ::Float
218
+ def duration
219
+ seconds = self
220
+
221
+ if seconds > 60
222
+ seconds = seconds.to_i
223
+ minutes = seconds / 60
224
+ seconds = seconds % 60
225
+ end
226
+
227
+ if minutes && minutes > 60
228
+ hours = minutes / 60
229
+ minutes = minutes % 60
230
+ end
231
+
232
+ duration_str = "#{seconds}s"
233
+ duration_str = "#{minutes}m #{duration_str}" if minutes
234
+ duration_str = "#{hours}h #{duration_str}" if hours
235
+
236
+ duration_str
237
+ end
238
+ end
239
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ectoplasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2024-01-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Adds some extension methods to build in types to add prettier console
14
14
  output
@@ -18,27 +18,15 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - ".github/workflows/build.yml"
22
- - ".github/workflows/gem-push.yml"
23
- - ".gitignore"
24
- - ".rubocop.yml"
25
- - CHANGELOG.md
26
- - Gemfile
27
- - LICENSE.txt
28
- - README.md
29
- - Rakefile
30
- - bin/console
31
- - bin/setup
32
- - ectoplasm.gemspec
33
21
  - lib/ectoplasm.rb
34
- homepage: https://bitbucket.org/cneubaur/ectoplasm-ruby
22
+ homepage: https://github.com/cneubauer/ectoplasm
35
23
  licenses:
36
- - MIT
24
+ - GPL-3.0-or-later
37
25
  metadata:
38
- homepage_uri: https://bitbucket.org/cneubaur/ectoplasm-ruby
39
- source_code_uri: https://bitbucket.org/cneubaur/ectoplasm-ruby
40
- changelog_uri: https://bitbucket.org/cneubaur/ectoplasm-ruby/src/master/CHANGELOG.md
41
- post_install_message:
26
+ homepage_uri: https://github.com/cneubauer/ectoplasm
27
+ source_code_uri: https://github.com/cneubauer/ectoplasm
28
+ changelog_uri: https://github.com/cneubauer/ectoplasm/blob/main/CHANGELOG.md
29
+ post_install_message:
42
30
  rdoc_options: []
43
31
  require_paths:
44
32
  - lib
@@ -46,15 +34,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
34
  requirements:
47
35
  - - ">="
48
36
  - !ruby/object:Gem::Version
49
- version: 2.5.0
37
+ version: 3.0.0
50
38
  required_rubygems_version: !ruby/object:Gem::Requirement
51
39
  requirements:
52
40
  - - ">="
53
41
  - !ruby/object:Gem::Version
54
42
  version: '0'
55
43
  requirements: []
56
- rubygems_version: 3.3.7
57
- signing_key:
44
+ rubygems_version: 3.3.26
45
+ signing_key:
58
46
  specification_version: 4
59
47
  summary: A helper library for console output
60
48
  test_files: []
@@ -1,27 +0,0 @@
1
- name: Build
2
-
3
- on:
4
- push:
5
- branches:
6
- - develop
7
-
8
- permissions:
9
- contents: read
10
-
11
- jobs:
12
- build:
13
- name: Test and Build
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/checkout@v3
17
- - name: Set up Ruby
18
- uses: ruby/setup-ruby@v1
19
- with:
20
- ruby-version: '3.1'
21
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
22
- - name: Style check
23
- run: bundle exec rubocop
24
- - name: Run tests
25
- run: bundle exec rspec spec
26
- - name: Build gem
27
- run: bundle exec rake build
@@ -1,44 +0,0 @@
1
- name: Ruby Gem
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*.*.*'
7
-
8
- jobs:
9
- build:
10
- name: Build and Publish
11
- runs-on: ubuntu-latest
12
- permissions:
13
- contents: read
14
- packages: write
15
-
16
- steps:
17
- - uses: actions/checkout@v3
18
- - name: Set up Ruby
19
- uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: '3.1'
22
-
23
- - name: Publish to GPR
24
- run: |
25
- mkdir -p $HOME/.gem
26
- touch $HOME/.gem/credentials
27
- chmod 0600 $HOME/.gem/credentials
28
- printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
- gem build *.gemspec
30
- gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
31
- env:
32
- GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
33
- OWNER: ${{ github.repository_owner }}
34
-
35
- - name: Publish to RubyGems
36
- run: |
37
- mkdir -p $HOME/.gem
38
- touch $HOME/.gem/credentials
39
- chmod 0600 $HOME/.gem/credentials
40
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
41
- gem build *.gemspec
42
- gem push *.gem
43
- env:
44
- GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- vscode/
2
- *.lock
3
- *.gem