kungfuig 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kungfuig.rb +2 -6
- data/lib/kungfuig/jobber.rb +15 -1
- data/lib/kungfuig/version.rb +1 -1
- metadata +2 -3
- data/lib/kungfuig/color.rb +0 -286
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc4658d114e15ae6587f426fd6484f73ac507d49
|
4
|
+
data.tar.gz: fd0ba43d7d5f10f1d148c32fccb8b22d15bf1269
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 088b8cc7fa2c5dde35d5133eb24eedeac49667c072246492e6924dd84b2995ee3e07ea9ea601122fc918f35a5fbfb68129b7f74b1da2c6956a4a30de3bf724c0
|
7
|
+
data.tar.gz: 5425c1425ed7ed78e3aecfadebe29410049798f14129b1797a9961cc4d4c38d1d34d4699c3ca9eef723ad7d3d650ebd77460271a272569d9324080d43b4e4331
|
data/lib/kungfuig.rb
CHANGED
@@ -2,7 +2,6 @@ require 'yaml'
|
|
2
2
|
require 'hashie'
|
3
3
|
|
4
4
|
require 'kungfuig/version'
|
5
|
-
require 'kungfuig/color'
|
6
5
|
require 'kungfuig/aspector'
|
7
6
|
require 'kungfuig/prepender'
|
8
7
|
|
@@ -12,11 +11,7 @@ module Kungfuig
|
|
12
11
|
# rubocop:disable Style/MethodName
|
13
12
|
def ✍(receiver: nil, method: nil, result: nil, args: nil, **params)
|
14
13
|
require 'logger'
|
15
|
-
|
16
|
-
message = receiver.is_a?(String) ? "#{receiver} | #{method}" : "#{receiver.class}##{method}"
|
17
|
-
"#{Color.to_xterm256(message, :info)} called with «#{Color.to_xterm256(args.inspect, :success)}» and returned «#{result || 'nothing (was it before aspect?)'}»".tap do |m|
|
18
|
-
@✍.debug m
|
19
|
-
end
|
14
|
+
Logger.new($stdout).debug({receiver: receiver, method: method, result: result, args: args, **params}.inspect)
|
20
15
|
end
|
21
16
|
module_function :✍
|
22
17
|
# rubocop:enable Style/MethodName
|
@@ -35,6 +30,7 @@ module Kungfuig
|
|
35
30
|
rescue
|
36
31
|
raise ArgumentError, "#{__callee__} expects valid YAML configuration string (misspelled file name?). Got:\n#{hos.inspect}"
|
37
32
|
end
|
33
|
+
when ->(h) { h.respond_to?(:to_h) } then Hashie::Mash.new(h.to_h)
|
38
34
|
when ->(h) { h.respond_to?(:to_hash) } then Hashie::Mash.new(h.to_hash)
|
39
35
|
else
|
40
36
|
fail ArgumentError.new "#{__callee__} accepts either String or Hash as parameter."
|
data/lib/kungfuig/jobber.rb
CHANGED
@@ -32,10 +32,23 @@ module Kungfuig
|
|
32
32
|
class Jobber
|
33
33
|
RESPOND_TO = ->(m, r) { r.respond_to? m.to_sym }
|
34
34
|
|
35
|
+
# this is an ugly hack unless I understand why digest gets corrupted sometimes
|
36
|
+
class UglyHack
|
37
|
+
def self.cleanup_digest(digest)
|
38
|
+
case digest
|
39
|
+
when String then digest
|
40
|
+
when Symbol then digest.to_s
|
41
|
+
when Hash then digest[:digest] || digest['digest'] || digest.inspect
|
42
|
+
else digest.inspect
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
35
47
|
class Dummy
|
36
48
|
prepend Kungfuig::Worker
|
37
49
|
|
38
50
|
def perform digest: nil, delay: nil, worker: nil, worker_params: nil
|
51
|
+
digest = UglyHack.cleanup_digest(digest)
|
39
52
|
Sidekiq.redis { |redis| redis.set(digest, worker_params.to_json) }
|
40
53
|
DummyExecutor.perform_in(delay, digest: digest, worker: worker)
|
41
54
|
end
|
@@ -45,13 +58,14 @@ module Kungfuig
|
|
45
58
|
prepend Kungfuig::Worker
|
46
59
|
|
47
60
|
def perform digest: nil, worker: nil
|
61
|
+
digest = UglyHack.cleanup_digest(digest)
|
48
62
|
params = Sidekiq.redis do |redis|
|
49
63
|
redis.multi do
|
50
64
|
redis.get(digest)
|
51
65
|
redis.del(digest)
|
52
66
|
end
|
53
67
|
end
|
54
|
-
Kernel.const_get(worker).perform_async(atomize_keys(params.first)) if params.last > 0
|
68
|
+
Kernel.const_get(worker).perform_async(**atomize_keys(params.first)) if params.last > 0
|
55
69
|
end
|
56
70
|
|
57
71
|
private
|
data/lib/kungfuig/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kungfuig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kantox LTD
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -209,7 +209,6 @@ files:
|
|
209
209
|
- kungfuig.png
|
210
210
|
- lib/kungfuig.rb
|
211
211
|
- lib/kungfuig/aspector.rb
|
212
|
-
- lib/kungfuig/color.rb
|
213
212
|
- lib/kungfuig/jobber.rb
|
214
213
|
- lib/kungfuig/prepender.rb
|
215
214
|
- lib/kungfuig/version.rb
|
data/lib/kungfuig/color.rb
DELETED
@@ -1,286 +0,0 @@
|
|
1
|
-
module Kungfuig
|
2
|
-
# rubocop:disable Metrics/ClassLength
|
3
|
-
# Dealing with colors
|
4
|
-
class Color
|
5
|
-
# Copyright (c) 2007 McClain Looney
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the "Software"), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in
|
15
|
-
# all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
-
# THE SOFTWARE.
|
24
|
-
|
25
|
-
# Implements a color (r,g,b + a) with conversion to/from web format (eg #aabbcc), and
|
26
|
-
# with a number of utilities to lighten, darken and blend values.
|
27
|
-
|
28
|
-
attr_reader :r, :g, :b, :a
|
29
|
-
|
30
|
-
# Table for conversion to hex
|
31
|
-
HEXVAL = ('0'..'9').to_a.concat(('A'..'F').to_a).freeze
|
32
|
-
# Default value for #darken, #lighten etc.
|
33
|
-
BRIGHTNESS_DEFAULT = 0.2
|
34
|
-
|
35
|
-
# Constructor. Inits to white (#FFFFFF) by default, or accepts any params
|
36
|
-
# supported by #parse.
|
37
|
-
def initialize(*args)
|
38
|
-
@r = 255
|
39
|
-
@g = 255
|
40
|
-
@b = 255
|
41
|
-
@a = 255
|
42
|
-
|
43
|
-
if args.size.between?(3, 4)
|
44
|
-
self.r = args[0]
|
45
|
-
self.g = args[1]
|
46
|
-
self.b = args[2]
|
47
|
-
self.a = args[3] if args[3]
|
48
|
-
else
|
49
|
-
set(*args)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# All-purpose setter - pass in another Color, '#000000', rgb vals... whatever
|
54
|
-
def set(*args)
|
55
|
-
val = Color.parse(*args)
|
56
|
-
unless val.nil?
|
57
|
-
self.r = val.r
|
58
|
-
self.g = val.g
|
59
|
-
self.b = val.b
|
60
|
-
self.a = val.a
|
61
|
-
end
|
62
|
-
self
|
63
|
-
end
|
64
|
-
|
65
|
-
# Test for equality, accepts string vals as well, eg Color.new('aaa') == '#AAAAAA' => true
|
66
|
-
def ==(other)
|
67
|
-
val = Color.parse(other)
|
68
|
-
return false if val.nil?
|
69
|
-
r == val.r && g == val.g && b == val.b && a == val.a
|
70
|
-
end
|
71
|
-
|
72
|
-
# Setters for individual channels - take 0-255 or '00'-'FF' values
|
73
|
-
%i(r g b a).each do |m|
|
74
|
-
define_method "#{m}=" do |val|
|
75
|
-
instance_variable_set("@#{m}", from_hex(val))
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
80
|
-
# rubocop:disable Metrics/MethodLength
|
81
|
-
# Attempt to read in a string and parse it into values
|
82
|
-
def self.parse(*args)
|
83
|
-
case args.size
|
84
|
-
when 0 then return nil
|
85
|
-
when 1
|
86
|
-
case val = args.first
|
87
|
-
when Color then val
|
88
|
-
when Fixnum then Color.new(val, val, val) # Single value, assume grayscale
|
89
|
-
when String
|
90
|
-
str = val.to_s.upcase[/[0-9A-F]{3,8}/] || ''
|
91
|
-
Color.new(*case str.length
|
92
|
-
when 3, 4 then str.scan(/[0-9A-F]/)
|
93
|
-
when 6, 8 then str.scan(/[0-9A-F]{2}/)
|
94
|
-
else 'FF'
|
95
|
-
end.map { |c| Integer("0x#{c}") })
|
96
|
-
end
|
97
|
-
when 2 # assume gray + alpha
|
98
|
-
val, alpha = args
|
99
|
-
Color.new(val, val, val, alpha)
|
100
|
-
when 3, 4 then Color.new(*args)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
# rubocop:enable Metrics/MethodLength
|
104
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
105
|
-
|
106
|
-
def inspect
|
107
|
-
id = format('%x', object_id << 1)
|
108
|
-
"#<#{self.class.name}:0x#{id.rjust(14, '0')} 💻=“\\e[#{to_esc(true)}#{to_esc(false)}\e[0mm” 🗔=“#{self}”>"
|
109
|
-
end
|
110
|
-
|
111
|
-
def to_s(add_hash = true)
|
112
|
-
trans? ? to_rgba(add_hash) : to_rgb(add_hash)
|
113
|
-
end
|
114
|
-
|
115
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
116
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
117
|
-
# rubocop:disable Metrics/ParameterLists
|
118
|
-
# Color as used in 256-color terminal escape sequences
|
119
|
-
def to_esc(surround = true, bold: true, italic: false, underline: false, reverse: false, foreground: true)
|
120
|
-
result = if grayscale?
|
121
|
-
(r > 239) ? 15 : (r / 10).floor + 232
|
122
|
-
else
|
123
|
-
16 + 36 * (r / 51).floor + 6 * (g / 51).floor + (b / 51).floor
|
124
|
-
end
|
125
|
-
|
126
|
-
esc = [
|
127
|
-
bold ? '01' : nil,
|
128
|
-
italic ? '03' : nil,
|
129
|
-
underline ? '04' : nil,
|
130
|
-
reverse ? '07' : nil,
|
131
|
-
foreground ? '38' : '48',
|
132
|
-
'05',
|
133
|
-
result
|
134
|
-
].compact.join(';')
|
135
|
-
|
136
|
-
surround ? "\e[#{esc}m" : esc
|
137
|
-
end
|
138
|
-
# rubocop:enable Metrics/ParameterLists
|
139
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
140
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
141
|
-
|
142
|
-
def to_rgb(add_hash = true)
|
143
|
-
(add_hash ? '#' : '') + to_hex(r) + to_hex(g) + to_hex(b)
|
144
|
-
end
|
145
|
-
|
146
|
-
def to_rgba(add_hash = true)
|
147
|
-
to_rgb(add_hash) + to_hex(a)
|
148
|
-
end
|
149
|
-
|
150
|
-
def opaque?
|
151
|
-
@a == 255
|
152
|
-
end
|
153
|
-
|
154
|
-
def trans?
|
155
|
-
!opaque?
|
156
|
-
end
|
157
|
-
|
158
|
-
def grayscale?
|
159
|
-
@r == @g && @g == @b
|
160
|
-
end
|
161
|
-
|
162
|
-
# Lighten color towards white. 0.0 is a no-op, 1.0 will return #FFFFFF
|
163
|
-
def lighten(amt = BRIGHTNESS_DEFAULT)
|
164
|
-
return self if amt <= 0
|
165
|
-
return WHITE if amt >= 1.0
|
166
|
-
Color.new(self).tap do |val|
|
167
|
-
val.r += ((255 - val.r) * amt).to_i
|
168
|
-
val.g += ((255 - val.g) * amt).to_i
|
169
|
-
val.b += ((255 - val.b) * amt).to_i
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# In place version of #lighten
|
174
|
-
def lighten!(amt = BRIGHTNESS_DEFAULT)
|
175
|
-
set(lighten(amt))
|
176
|
-
end
|
177
|
-
|
178
|
-
# Darken a color towards full black. 0.0 is a no-op, 1.0 will return #000000
|
179
|
-
def darken(amt = BRIGHTNESS_DEFAULT)
|
180
|
-
return self if amt <= 0
|
181
|
-
return BLACK if amt >= 1.0
|
182
|
-
Color.new(self).tap do |val|
|
183
|
-
val.r -= (val.r * amt).to_i
|
184
|
-
val.g -= (val.g * amt).to_i
|
185
|
-
val.b -= (val.b * amt).to_i
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
# In place version of #darken
|
190
|
-
def darken!(amt = BRIGHTNESS_DEFAULT)
|
191
|
-
set(darken(amt))
|
192
|
-
end
|
193
|
-
|
194
|
-
# Convert to grayscale, using perception-based weighting
|
195
|
-
def grayscale
|
196
|
-
Color.new(self).tap do |val|
|
197
|
-
val.r = val.g = val.b = (0.2126 * val.r + 0.7152 * val.g + 0.0722 * val.b)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
# In place version of #grayscale
|
202
|
-
def grayscale!
|
203
|
-
set(grayscale)
|
204
|
-
end
|
205
|
-
|
206
|
-
# rubocop:disable Metrics/AbcSize
|
207
|
-
# Blend to a color amt % towards another color value, eg
|
208
|
-
# red.blend(blue, 0.5) will be purple, white.blend(black, 0.5) will be gray, etc.
|
209
|
-
def blend(other, amt)
|
210
|
-
other = Color.parse(other)
|
211
|
-
return Color.new(self) if amt <= 0 || other.nil?
|
212
|
-
return Color.new(other) if amt >= 1.0
|
213
|
-
Color.new(self).tap do |val|
|
214
|
-
val.r += ((other.r - val.r) * amt).to_i
|
215
|
-
val.g += ((other.g - val.g) * amt).to_i
|
216
|
-
val.b += ((other.b - val.b) * amt).to_i
|
217
|
-
end
|
218
|
-
end
|
219
|
-
# rubocop:enable Metrics/AbcSize
|
220
|
-
|
221
|
-
# In place version of #blend
|
222
|
-
def blend!(other, amt)
|
223
|
-
set(blend(other, amt))
|
224
|
-
self
|
225
|
-
end
|
226
|
-
|
227
|
-
# Class-level version for explicit blends of two values, useful with constants
|
228
|
-
def self.blend(col1, col2, amt)
|
229
|
-
col1, col2 = [col1, col2].map { |c| Color.parse c }
|
230
|
-
col1.blend(col2, amt)
|
231
|
-
end
|
232
|
-
|
233
|
-
# rubocop:disable Metrics/ParameterLists
|
234
|
-
def self.to_xterm256(text, color, bold: true, italic: false, underline: false, reverse: false, foreground: true)
|
235
|
-
color = Color.preset(color) unless color.is_a?(Color)
|
236
|
-
[
|
237
|
-
color.to_esc(true, bold: bold, italic: italic, underline: underline, reverse: reverse, foreground: foreground),
|
238
|
-
text,
|
239
|
-
"\e[0m"
|
240
|
-
].join
|
241
|
-
end
|
242
|
-
# rubocop:enable Metrics/ParameterLists
|
243
|
-
|
244
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
245
|
-
def self.preset type
|
246
|
-
Color.parse case type
|
247
|
-
when :label then '#999999'
|
248
|
-
when :success then '#468847'
|
249
|
-
when :warning then '#F89406'
|
250
|
-
when :important then '#B94A48'
|
251
|
-
when :fatal then '#B94A48'
|
252
|
-
when :error then '#FF0000'
|
253
|
-
when :info then '#3A87AD'
|
254
|
-
when :inverse then '#333333'
|
255
|
-
else type
|
256
|
-
end
|
257
|
-
end
|
258
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
259
|
-
|
260
|
-
protected
|
261
|
-
|
262
|
-
# Convert int to string hex, eg 255 => 'FF'
|
263
|
-
def to_hex(val)
|
264
|
-
HEXVAL[val / 16] + HEXVAL[val % 16]
|
265
|
-
end
|
266
|
-
|
267
|
-
# Convert int or string to int, eg 80 => 80, 'FF' => 255, '7' => 119
|
268
|
-
def from_hex(val)
|
269
|
-
if val.is_a?(String)
|
270
|
-
# Double up if single char form
|
271
|
-
val *= 2 if val.size == 1
|
272
|
-
# Convert to integer
|
273
|
-
val = val.hex
|
274
|
-
end
|
275
|
-
# Clamp
|
276
|
-
val = 0 if val < 0
|
277
|
-
val = 255 if val > 255
|
278
|
-
val
|
279
|
-
end
|
280
|
-
|
281
|
-
# Some constants for general use
|
282
|
-
WHITE = Color.new(255, 255, 255).freeze
|
283
|
-
BLACK = Color.new(0, 0, 0).freeze
|
284
|
-
end
|
285
|
-
# rubocop:enable Metrics/ClassLength
|
286
|
-
end
|