ruby_smart-support 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +11 -15
- data/README.md +23 -0
- data/docs/CHANGELOG.md +10 -0
- data/lib/ruby_smart/support/core_ext/ruby/enumerator.rb +19 -0
- data/lib/ruby_smart/support/core_ext.rb +1 -0
- data/lib/ruby_smart/support/gem_info.rb +12 -0
- data/lib/ruby_smart/support/gem_version.rb +1 -1
- data/lib/ruby_smart/support/thread_info.rb +10 -6
- data/ruby_smart-support.gemspec +2 -0
- metadata +35 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1775b5245ce4c9ca6de799fc00e1144c3b9025f75c1dc2ddbeea2aefc45e7d66
|
4
|
+
data.tar.gz: 72749e09f012e15c978a50e03ecc2dc3c7a20bdefeda9b461b127174702e8802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5073cc0aac8b4a59b79fc3809b2319bac5dd9cba53b2bd0c73110f40ef6aaa280a352b9b393c29c7a6745a4960b58536cdb54a743f5c2029734454048b4e1d2
|
7
|
+
data.tar.gz: bcc21095d341d019e833fe3bfb0fd39ed2bb0acaf18ac50a6a60a568a573349f465ab106dfe552e8f61e83685096b82fefd254bb4609ca0ad263a02e7ede6af2
|
data/.github/workflows/ruby.yml
CHANGED
@@ -18,21 +18,17 @@ permissions:
|
|
18
18
|
|
19
19
|
jobs:
|
20
20
|
test:
|
21
|
-
|
22
|
-
runs-on: ubuntu-latest
|
23
21
|
strategy:
|
22
|
+
fail-fast: false
|
24
23
|
matrix:
|
25
|
-
|
26
|
-
|
24
|
+
os: [ubuntu-latest]
|
25
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
26
|
+
ruby: ['3.2', '3.1', '3.0', '2.7', '2.6']
|
27
|
+
runs-on: ${{ matrix.os }}
|
27
28
|
steps:
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
with:
|
35
|
-
ruby-version: ${{ matrix.ruby-version }}
|
36
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
-
- name: Run tests
|
38
|
-
run: bundle exec rake
|
29
|
+
- uses: actions/checkout@v3
|
30
|
+
- uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- run: bundle exec rake
|
data/README.md
CHANGED
@@ -40,6 +40,7 @@ Or install it yourself as:
|
|
40
40
|
* *Hash* `#to_md5`, `#product`
|
41
41
|
* *Object* `#numeric?`, `#boolean?`, `#missing_method?`, `#alias_missing_method`
|
42
42
|
* *String* `#to_boolean`, `#to_md5`
|
43
|
+
* *Enumerator* `#from_hash`
|
43
44
|
|
44
45
|
* extensions for activesupport
|
45
46
|
* *Hash* `#only!`, `#without!`, `#deep_reject`
|
@@ -85,6 +86,7 @@ ThreadInfo.info
|
|
85
86
|
* .console?
|
86
87
|
* .irb?
|
87
88
|
* .pry?
|
89
|
+
* .sidekiq?
|
88
90
|
* .server?
|
89
91
|
* .rails_console?
|
90
92
|
* .io_console?
|
@@ -119,6 +121,11 @@ GemInfo.installed
|
|
119
121
|
GemInfo.loaded
|
120
122
|
# > {'bundler' => '2.2.30', ...}
|
121
123
|
|
124
|
+
# returns a hash of all loaded gems with its current license
|
125
|
+
# (gems from the Gemfile)
|
126
|
+
GemInfo.licenses
|
127
|
+
# > {'bundler' => 'MIT', ...}
|
128
|
+
|
122
129
|
# returns an array of all active gems
|
123
130
|
GemInfo.active
|
124
131
|
# > ['bundler', ...]
|
@@ -155,6 +162,7 @@ GemInfo.match?( '0.1.0', '~> 1.1.0',)
|
|
155
162
|
* .installed?
|
156
163
|
* .loaded
|
157
164
|
* .loaded?
|
165
|
+
* .licenses
|
158
166
|
* .active
|
159
167
|
* .active?
|
160
168
|
* .features
|
@@ -195,6 +203,21 @@ rake db:migrate
|
|
195
203
|
# > executes append block
|
196
204
|
```
|
197
205
|
|
206
|
+
|
207
|
+
## Enumerator extensions
|
208
|
+
|
209
|
+
With the new method `from_hash` you can now easily map values from an array of hashes.
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
ary = [{a: 34, b: 12}, {a: 19, c: 4}, {b: 3, c: 11}]
|
213
|
+
ary.map.from_hash(:a)
|
214
|
+
# > [34, 19, nil]
|
215
|
+
|
216
|
+
```
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
198
221
|
-----
|
199
222
|
|
200
223
|
## Docs
|
data/docs/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# RubySmart::Support - CHANGELOG
|
2
2
|
|
3
|
+
## [1.4.0] - 2023-10-19
|
4
|
+
* **[ref]** `RubySmart::Support::ThreadInfo.sidekiq?`-detection to determinate if the current thread is a sidekiq process
|
5
|
+
|
6
|
+
## [1.3.0] - 2023-08-08
|
7
|
+
* **[add]** `Enumerator.from_hash` to easily resolve values from Array-of-Hashes (use: ary.map.from_hash(key))
|
8
|
+
* **[add]** `RubySmart::Support::GemInfo.licenses` to resolve a hash of licences per loaded gem
|
9
|
+
* **[fix]** `RubySmart::Support::ThreadInfo.winsize`-detection for debug-ENVs
|
10
|
+
* **[ref]** `RubySmart::Support::ThreadInfo.name` to show full application namespace
|
11
|
+
* **[ref]** `RubySmart::Support::ThreadInfo.info` to show a optimized info-string
|
12
|
+
|
3
13
|
## [1.2.0] - 2023-01-24
|
4
14
|
* **[ref]** `GemInfo` methods (active -> required & active? -> required?)
|
5
15
|
* **[ref]** simplify `GemInfo.match?`method
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
unless Enumerator.method_defined? :from_hash
|
4
|
+
class Enumerator
|
5
|
+
# returns a new array with only values from provided key.
|
6
|
+
# The Enumerator must be an array of hashes.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# ary = [{a: 34, b: 12}, {a: 19, c: 4}, {b: 3, c: 11}]
|
10
|
+
# ary.map.from_hash(:a)
|
11
|
+
# > [34, 19, nil]
|
12
|
+
#
|
13
|
+
# @param [Object] key
|
14
|
+
# @return [Array] ary
|
15
|
+
def from_hash(key)
|
16
|
+
map &->(item){item[key]}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -53,6 +53,18 @@ module RubySmart
|
|
53
53
|
Hash[::Gem.loaded_specs.values.map { |g| [g.name, g.version.to_s] }.sort]
|
54
54
|
end
|
55
55
|
|
56
|
+
# returns a hash of all loaded gems with it's licenses
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
#
|
60
|
+
# GemInfo.licenses
|
61
|
+
# # > {'bundler' => 'MIT', 'hashery' => 'BSD-2-Clause'}
|
62
|
+
#
|
63
|
+
# @return [Hash{<name> => <license>}] licenses
|
64
|
+
def self.licenses
|
65
|
+
Hash[::Gem.loaded_specs.values.map { |g| [g.name, g.license || '?'] }.sort]
|
66
|
+
end
|
67
|
+
|
56
68
|
# returns true if the provided gem name is loaded (defined within any Gemfile), but must not be required yet.
|
57
69
|
# the optional version requirement matches against the loaded version
|
58
70
|
#
|
@@ -7,7 +7,7 @@ module RubySmart
|
|
7
7
|
module ThreadInfo
|
8
8
|
|
9
9
|
# defines a array of types which will be checked by resolving the current thread type
|
10
|
-
TYPE_ORDER = [:rake, :console, :server].freeze
|
10
|
+
TYPE_ORDER = [:rake, :console, :sidekiq, :server].freeze
|
11
11
|
|
12
12
|
# returns true if this is a running rake process
|
13
13
|
# @return [Boolean]
|
@@ -39,6 +39,12 @@ module RubySmart
|
|
39
39
|
!!defined?(Pry)
|
40
40
|
end
|
41
41
|
|
42
|
+
# returns true if this is a running 'sidekiq' server process.
|
43
|
+
# @return [Boolean]
|
44
|
+
def self.sidekiq?
|
45
|
+
!!defined?(Sidekiq) && Sidekiq.server?
|
46
|
+
end
|
47
|
+
|
42
48
|
# returns true if this is a running server process.
|
43
49
|
# currently only detects rails
|
44
50
|
# @return [Boolean]
|
@@ -98,7 +104,7 @@ module RubySmart
|
|
98
104
|
# @return [String] name
|
99
105
|
def self.name
|
100
106
|
return Rake.application.top_level_tasks.first.to_s if rake?
|
101
|
-
return Rails.application.
|
107
|
+
return Rails.application.class.name if rails?
|
102
108
|
''
|
103
109
|
end
|
104
110
|
|
@@ -112,9 +118,7 @@ module RubySmart
|
|
112
118
|
# returns the thread type string
|
113
119
|
# @return [String] thread-info string
|
114
120
|
def self.info
|
115
|
-
|
116
|
-
strs << " :: #{name}" if name != ''
|
117
|
-
strs.join ' '
|
121
|
+
"$(#{id}) -> [##{process_object_id}] @ #{type} :: #{self.name}"
|
118
122
|
end
|
119
123
|
|
120
124
|
# returns true if thread has a 'window'
|
@@ -127,7 +131,7 @@ module RubySmart
|
|
127
131
|
# @return [Array<rows, columns>] winsize
|
128
132
|
def self.winsize
|
129
133
|
return IO.console.winsize if io_console?
|
130
|
-
return [ENV['ROWS'], ENV['COLUMNS']] unless ENV['ROWS'].nil?
|
134
|
+
return [ENV['ROWS'].to_i, ENV['COLUMNS'].to_i] unless ENV['ROWS'].nil? || ENV['COLUMNS'].nil?
|
131
135
|
[0, 0]
|
132
136
|
end
|
133
137
|
|
data/ruby_smart-support.gemspec
CHANGED
@@ -36,4 +36,6 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency 'rake', '~> 13.0'
|
37
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
38
|
spec.add_development_dependency 'yard', '~> 0.9'
|
39
|
+
spec.add_development_dependency 'yard-activesupport-concern', '~> 0.0.1'
|
40
|
+
spec.add_development_dependency 'yard-relative_markdown_links', '>= 0.4'
|
39
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_smart-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Gonsior
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard-activesupport-concern
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard-relative_markdown_links
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.4'
|
83
111
|
description: 'RubySmart::Support is a toolkit of support libraries for Ruby - major
|
84
112
|
features includes GemInfo & ThreadInfo, as well core extensions for Ruby & activesupport
|
85
113
|
(if installed).
|
@@ -111,6 +139,7 @@ files:
|
|
111
139
|
- lib/ruby_smart/support/core_ext/rails/info.rb
|
112
140
|
- lib/ruby_smart/support/core_ext/rake/task.rb
|
113
141
|
- lib/ruby_smart/support/core_ext/ruby/array.rb
|
142
|
+
- lib/ruby_smart/support/core_ext/ruby/enumerator.rb
|
114
143
|
- lib/ruby_smart/support/core_ext/ruby/float.rb
|
115
144
|
- lib/ruby_smart/support/core_ext/ruby/hash.rb
|
116
145
|
- lib/ruby_smart/support/core_ext/ruby/object.rb
|
@@ -130,7 +159,7 @@ metadata:
|
|
130
159
|
documentation_uri: https://rubydoc.info/gems/ruby_smart-support
|
131
160
|
changelog_uri: https://github.com/ruby-smart/support/blob/main/docs/CHANGELOG.md
|
132
161
|
allowed_push_host: https://rubygems.org
|
133
|
-
post_install_message:
|
162
|
+
post_install_message:
|
134
163
|
rdoc_options: []
|
135
164
|
require_paths:
|
136
165
|
- lib
|
@@ -145,8 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
174
|
- !ruby/object:Gem::Version
|
146
175
|
version: '0'
|
147
176
|
requirements: []
|
148
|
-
rubygems_version: 3.
|
149
|
-
signing_key:
|
177
|
+
rubygems_version: 3.4.10
|
178
|
+
signing_key:
|
150
179
|
specification_version: 4
|
151
180
|
summary: A toolkit of support libraries including GemInfo, ThreadInfo, Ruby core extensions
|
152
181
|
& optionally activesupport extensions
|