vv 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vv/cli.rb +3 -3
- data/lib/vv/file_methods.rb +42 -8
- data/lib/vv/float_methods.rb +47 -0
- data/lib/vv/hash_methods.rb +15 -0
- data/lib/vv/integer_methods.rb +31 -17
- data/lib/vv/string_methods.rb +30 -4
- data/lib/vv/utility/automate.rb +18 -1
- data/lib/vv/version.rb +1 -1
- data/lib/vv.rb +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f3bcbbe7ea69583dce95c3b9d9a702fda226a2bb9e63f524c0a76cc18b69142
|
4
|
+
data.tar.gz: 36b73375b12feb1240c7361309ad1b346e0893291c1d068eafd2f2eca20d8aac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09b06bd73467b0f00bf81fc89ac494b153db055042ddbad586dc332b1ca460cb217728860a311ffb09b7f8ebd464dc1eb7d8153a3ce51d4a6b140cf84ecb9641'
|
7
|
+
data.tar.gz: d8401e963170293b4a591f49ef040350d3a6fdb557102b741717bd89ebbd40deb3f7984e5f71a0281cbe6344b6a904c96833a328ff60e59981342c6b811c3d43
|
data/lib/vv/cli.rb
CHANGED
@@ -38,9 +38,9 @@ module VV
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def set_default_paths
|
41
|
-
@config_path ||= File.
|
42
|
-
@cache_path ||= File.
|
43
|
-
@data_path ||= File.
|
41
|
+
@config_path ||= File.config_home! name_version
|
42
|
+
@cache_path ||= File.cache_home! name_version
|
43
|
+
@data_path ||= File.data_home! name_version
|
44
44
|
end
|
45
45
|
|
46
46
|
def name
|
data/lib/vv/file_methods.rb
CHANGED
@@ -153,29 +153,35 @@ module VV
|
|
153
153
|
alias_method :move_dir_into, :move_directory_into
|
154
154
|
alias_method :mv_dir_into, :move_directory_into
|
155
155
|
|
156
|
-
def config_home
|
156
|
+
def config_home sub_directory=nil
|
157
157
|
path = ENV['XDG_CACHE_HOME']
|
158
|
-
return path unless path.blank?
|
159
158
|
path ||= File.join ENV['HOME'], ".config"
|
159
|
+
|
160
|
+
return path unless sub_directory
|
161
|
+
|
162
|
+
File.join path, sub_directory
|
160
163
|
end
|
161
164
|
alias_method :xdg_config_home, :config_home
|
162
165
|
|
163
166
|
# Where application specific files should be stored
|
164
|
-
def data_home
|
167
|
+
def data_home sub_directory=nil
|
165
168
|
path = ENV['XDG_DATA_HOME']
|
166
|
-
return path unless path.blank?
|
167
169
|
path ||= File.join ENV['HOME'], ".local", "share"
|
170
|
+
|
171
|
+
return path unless sub_directory
|
172
|
+
|
173
|
+
File.join path, sub_directory
|
168
174
|
end
|
169
175
|
alias_method :output_home, :data_home
|
170
176
|
alias_method :xdg_data_home, :data_home
|
171
177
|
|
172
178
|
def cache_home sub_directory=nil
|
173
|
-
|
174
|
-
|
179
|
+
path = ENV['XDG_CACHE_HOME']
|
180
|
+
path ||= File.join ENV['HOME'], ".cache"
|
175
181
|
|
176
|
-
return
|
182
|
+
return path unless sub_directory
|
177
183
|
|
178
|
-
File.join
|
184
|
+
File.join path, sub_directory
|
179
185
|
end
|
180
186
|
alias_method :xdg_cache_home, :cache_home
|
181
187
|
|
@@ -186,11 +192,29 @@ module VV
|
|
186
192
|
end
|
187
193
|
alias_method :xdg_cache_home!, :cache_home!
|
188
194
|
|
195
|
+
def config_home! sub_directory
|
196
|
+
path = config_home sub_directory
|
197
|
+
File.make_dir_if_not_exists path
|
198
|
+
path
|
199
|
+
end
|
200
|
+
alias_method :xdg_config_home!, :config_home!
|
201
|
+
|
202
|
+
def data_home! sub_directory
|
203
|
+
path = data_home sub_directory
|
204
|
+
File.make_dir_if_not_exists path
|
205
|
+
path
|
206
|
+
end
|
207
|
+
alias_method :xdg_data_home!, :data_home!
|
208
|
+
|
189
209
|
def make_directory_if_not_exists directory
|
190
210
|
FileUtils.mkdir_p(directory).first
|
191
211
|
end
|
192
212
|
alias_method :make_dir_if_not_exists,
|
193
213
|
:make_directory_if_not_exists
|
214
|
+
alias_method :create_directory_if_not_exists,
|
215
|
+
:make_directory_if_not_exists
|
216
|
+
alias_method :create_dir_if_not_exists,
|
217
|
+
:make_directory_if_not_exists
|
194
218
|
|
195
219
|
def make_directory directory
|
196
220
|
FileUtils.mkdir(directory).first
|
@@ -208,6 +232,16 @@ module VV
|
|
208
232
|
alias_method :remove_dir, :remove_directory
|
209
233
|
alias_method :rm_dir, :remove_directory
|
210
234
|
|
235
|
+
def remove filepath, force: false
|
236
|
+
message = \
|
237
|
+
"Cowardly refusing to remove directory (see `remove_directory`)"
|
238
|
+
fail message if filepath.is_directory_path?
|
239
|
+
|
240
|
+
force ? FileUtils.rm_f(filepath) : FileUtils.rm(filepath)
|
241
|
+
end
|
242
|
+
alias_method :remove_file, :remove
|
243
|
+
alias_method :rm, :remove
|
244
|
+
|
211
245
|
end
|
212
246
|
|
213
247
|
def vv_readlines
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module VV
|
2
|
+
module FloatMethods
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def vv_included?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def vv_json nan_coerces: false,
|
17
|
+
infinity_coerces: false,
|
18
|
+
max: nil,
|
19
|
+
min: nil
|
20
|
+
|
21
|
+
fail "Expecting numeric value for `max`" if max.is_a? String
|
22
|
+
fail "Expecting numeric value for `min`" if min.is_a? String
|
23
|
+
|
24
|
+
message = \
|
25
|
+
"Infinite not convertable sans `infinity_coerces: true`. "
|
26
|
+
message += "Set `max` and `min` for non-null coercion."
|
27
|
+
fail message if infinite? unless infinity_coerces
|
28
|
+
|
29
|
+
message = \
|
30
|
+
"NaN not convertable sans `nan_coerces: true`."
|
31
|
+
fail message if self.nan? unless nan_coerces
|
32
|
+
|
33
|
+
return nil.to_json if nan?
|
34
|
+
|
35
|
+
use_max = ( max.present? and self > max )
|
36
|
+
use_max ||= ( infinite? and self > 0 )
|
37
|
+
return max.to_json if use_max
|
38
|
+
|
39
|
+
use_min = ( min.present? and self < min )
|
40
|
+
use_min ||= ( infinite? and self < 0 )
|
41
|
+
return min.to_json if use_min
|
42
|
+
|
43
|
+
JSON.dump(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/vv/hash_methods.rb
CHANGED
@@ -13,6 +13,21 @@ module VV
|
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
+
# See Float#vv_json.
|
17
|
+
# Intended for common sense json doc generation with reasonable
|
18
|
+
# length, depth, and size limits.
|
19
|
+
def vv_json
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
def symbolize_keys
|
24
|
+
transform_keys{ |key| key.to_sym }
|
25
|
+
end
|
26
|
+
|
27
|
+
def symbolize_keys!
|
28
|
+
transform_keys!{ |key| key.to_sym }
|
29
|
+
end
|
30
|
+
|
16
31
|
def stringify_keys
|
17
32
|
transform_keys{ |key| key.to_s }
|
18
33
|
end
|
data/lib/vv/integer_methods.rb
CHANGED
@@ -1,25 +1,39 @@
|
|
1
|
-
|
1
|
+
module VV
|
2
|
+
module IntegerMethods
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
characters String.dash
|
9
|
-
end
|
8
|
+
module ClassMethods
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def vv_included?
|
11
|
+
true
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
fail message if self < 0 and fail_on_negative
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
def spaces
|
17
|
+
characters String.space
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def dashes
|
21
|
+
characters String.dash
|
22
|
+
end
|
23
|
+
|
24
|
+
def characters character, fail_on_negative: false
|
25
|
+
message = "Expected single character, not #{character}."
|
26
|
+
fail ArgumentError, message if character.length > 1
|
24
27
|
|
28
|
+
message = "Expected non-negative integer, not `#{self}`."
|
29
|
+
fail message if self < 0 and fail_on_negative
|
30
|
+
|
31
|
+
( self > 0 ) ? ( character * self ) : String.empty_string
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_i!
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
25
39
|
end
|
data/lib/vv/string_methods.rb
CHANGED
@@ -296,10 +296,6 @@ module VV
|
|
296
296
|
raise
|
297
297
|
end
|
298
298
|
|
299
|
-
def to_i!
|
300
|
-
Integer(self)
|
301
|
-
end
|
302
|
-
|
303
299
|
def to_boolean
|
304
300
|
_true = self == "true"
|
305
301
|
return true if _true
|
@@ -313,6 +309,36 @@ module VV
|
|
313
309
|
raise RuntimeError, message
|
314
310
|
end
|
315
311
|
|
312
|
+
def parse notation: :json
|
313
|
+
message = "Only JSON support at this time."
|
314
|
+
fail NotImplementedError, message unless notation == :json
|
315
|
+
|
316
|
+
JSON.parse self
|
317
|
+
end
|
318
|
+
|
319
|
+
def parse_json
|
320
|
+
self.parse notation: :json
|
321
|
+
end
|
322
|
+
|
323
|
+
def to_h parse: :json, symbolize_keys: false
|
324
|
+
message = "Only JSON support at this time."
|
325
|
+
fail NotImplementedError, message unless parse == :json
|
326
|
+
|
327
|
+
response = self.parse_json
|
328
|
+
|
329
|
+
response.symbolize_keys! if symbolize_keys
|
330
|
+
|
331
|
+
return response if response.to_h == response
|
332
|
+
|
333
|
+
message = \
|
334
|
+
"Parse string was #{response.class}, instead of Hash."
|
335
|
+
fail message
|
336
|
+
end
|
337
|
+
|
338
|
+
def to_i!
|
339
|
+
Integer(self)
|
340
|
+
end
|
341
|
+
|
316
342
|
def readable_to_i
|
317
343
|
return self.to_i if self.number?
|
318
344
|
|
data/lib/vv/utility/automate.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module VV
|
2
|
+
|
3
|
+
# Automate runs standalone from the rest of the repo, so
|
4
|
+
# the code here intentionally avoids using helpers that
|
5
|
+
# VV adds to ruby classes.
|
6
|
+
|
2
7
|
module Automate
|
3
8
|
|
4
9
|
def version path:
|
@@ -55,7 +60,10 @@ module VV
|
|
55
60
|
end
|
56
61
|
module_function :version
|
57
62
|
|
58
|
-
def build( name: )
|
63
|
+
def build( name: , argv: nil )
|
64
|
+
simple = %w[ simple force ].include? argv.first
|
65
|
+
return build_simple name: name if simple
|
66
|
+
|
59
67
|
puts %x{ find lib/ | \\
|
60
68
|
xargs git ls-files --error-unmatch > /dev/null 2>&1 \\
|
61
69
|
|| ( echo && \\
|
@@ -71,6 +79,15 @@ module VV
|
|
71
79
|
end
|
72
80
|
module_function :build
|
73
81
|
|
82
|
+
def build_simple( name: )
|
83
|
+
puts %x{ rm #{name}-*.gem
|
84
|
+
gem uninstall --ignore-dependencies #{name} > /dev/null
|
85
|
+
gem build --force #{name}.gemspec
|
86
|
+
gem install --force --local $(readlink -f #{name}-*.gem | sort | tail -n 1 ) --pre
|
87
|
+
}
|
88
|
+
end
|
89
|
+
module_function :build_simple
|
90
|
+
|
74
91
|
def push( name: )
|
75
92
|
puts %x{ TAG_VERSION=$(./bin/version)
|
76
93
|
git push origin HEAD && \\
|
data/lib/vv/version.rb
CHANGED
data/lib/vv.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "json"
|
1
2
|
require "securerandom"
|
2
3
|
require "readline"
|
3
4
|
require "set"
|
@@ -48,6 +49,14 @@ class NilClass
|
|
48
49
|
include VV::NilMethods
|
49
50
|
end
|
50
51
|
|
52
|
+
class Integer
|
53
|
+
include VV::IntegerMethods
|
54
|
+
end
|
55
|
+
|
56
|
+
class Float
|
57
|
+
include VV::FloatMethods
|
58
|
+
end
|
59
|
+
|
51
60
|
class Random
|
52
61
|
include VV::RandomMethods
|
53
62
|
extend VV::RandomClassSettings
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Aysan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/vv/cli.rb
|
67
67
|
- lib/vv/false_methods.rb
|
68
68
|
- lib/vv/file_methods.rb
|
69
|
+
- lib/vv/float_methods.rb
|
69
70
|
- lib/vv/gem_methods.rb
|
70
71
|
- lib/vv/hash_methods.rb
|
71
72
|
- lib/vv/integer_methods.rb
|