vv 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vv.rb +5 -0
- data/lib/vv/array_methods.rb +4 -0
- data/lib/vv/float_methods.rb +1 -1
- data/lib/vv/hash_methods.rb +1 -4
- data/lib/vv/integer_methods.rb +49 -0
- data/lib/vv/nil_methods.rb +4 -0
- data/lib/vv/object_methods.rb +60 -42
- data/lib/vv/serialization/json.rb +88 -0
- data/lib/vv/set_methods.rb +37 -2
- data/lib/vv/string_methods.rb +14 -1
- data/lib/vv/symbol_methods.rb +12 -0
- data/lib/vv/utility/automate.rb +3 -2
- data/lib/vv/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f7b33e4bf1daadb65c4aa05ccc583213a0808f78f6bf7b6205da479fe05cf34
|
4
|
+
data.tar.gz: ab9838d4ebeb70a227c77fd871da29343ad64a138eb7e0e3cd1b921e374ec17c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 938ce048bb3d4d71230c96ff80160ef82f472ff2307c431d04ba50281fecd70fd9227c05e01ec08d12eef1c63d4cf46961a8b581c8f9bb7c3a21dccd98f86269
|
7
|
+
data.tar.gz: c466b8987c0ff65dcfdea6fc37e76a484c24be303877714ab57fcd251c5f0db0c190452d268ece3753d96610bf3f6397f788411a347c3d7ff85fcef13856055d
|
data/lib/vv.rb
CHANGED
@@ -12,6 +12,11 @@ require_relative "vv/set_methods"
|
|
12
12
|
Gem.require_files "vv/*.rb"
|
13
13
|
Gem.require_files "vv/style/*.rb"
|
14
14
|
Gem.require_files "vv/utility/*.rb"
|
15
|
+
Gem.require_files "vv/serialization/*.rb"
|
16
|
+
|
17
|
+
class Object
|
18
|
+
include VV::ObjectMethods
|
19
|
+
end
|
15
20
|
|
16
21
|
class Symbol
|
17
22
|
include VV::SymbolMethods
|
data/lib/vv/array_methods.rb
CHANGED
data/lib/vv/float_methods.rb
CHANGED
data/lib/vv/hash_methods.rb
CHANGED
@@ -13,11 +13,8 @@ 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
16
|
def vv_json
|
20
|
-
|
17
|
+
VV::JSON.generate self
|
21
18
|
end
|
22
19
|
|
23
20
|
def symbolize_keys
|
data/lib/vv/integer_methods.rb
CHANGED
@@ -13,6 +13,55 @@ module VV
|
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
+
def vv_json
|
17
|
+
self.to_json
|
18
|
+
end
|
19
|
+
|
20
|
+
def ceil_divide divisor
|
21
|
+
self % divisor > 0 ? ( self / divisor ) + 1 : self / divisor
|
22
|
+
end
|
23
|
+
|
24
|
+
def bits
|
25
|
+
bits_per_byte = 8
|
26
|
+
self.ceil_divide bits_per_byte
|
27
|
+
end
|
28
|
+
|
29
|
+
def kibibytes
|
30
|
+
self * 1024
|
31
|
+
end
|
32
|
+
alias_method :kibibyte, :kibibytes
|
33
|
+
alias_method :KiB, :kibibytes
|
34
|
+
|
35
|
+
def mebibytes
|
36
|
+
self.kibibytes * 1024
|
37
|
+
end
|
38
|
+
alias_method :mebibyte, :mebibytes
|
39
|
+
alias_method :MiB, :mebibytes
|
40
|
+
|
41
|
+
def gibibytes
|
42
|
+
self.mebibytes * 1024
|
43
|
+
end
|
44
|
+
alias_method :gibibyte, :gibibytes
|
45
|
+
alias_method :GiB, :gibibytes
|
46
|
+
|
47
|
+
def tebibytes
|
48
|
+
self.gibibytes * 1024
|
49
|
+
end
|
50
|
+
alias_method :tebibyte, :tebibytes
|
51
|
+
alias_method :TiB, :tebibytes
|
52
|
+
|
53
|
+
def pebibytes
|
54
|
+
self.tebibytes * 1024
|
55
|
+
end
|
56
|
+
alias_method :pebibyte, :pebibytes
|
57
|
+
alias_method :PiB, :pebibytes
|
58
|
+
|
59
|
+
def exbibytes
|
60
|
+
self.pebibytes * 1024
|
61
|
+
end
|
62
|
+
alias_method :exbibyte, :exbibytes
|
63
|
+
alias_method :EiB, :exbibytes
|
64
|
+
|
16
65
|
def spaces
|
17
66
|
characters String.space
|
18
67
|
end
|
data/lib/vv/nil_methods.rb
CHANGED
data/lib/vv/object_methods.rb
CHANGED
@@ -1,57 +1,75 @@
|
|
1
|
-
|
1
|
+
module VV
|
2
2
|
|
3
|
-
|
3
|
+
module ObjectMethods
|
4
4
|
|
5
|
-
|
6
|
-
respond_to?(:empty?) ? !!empty? : !self
|
7
|
-
end unless method_defined? :blank?
|
5
|
+
alias_method :responds_to?, :respond_to?
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
def set_attrs_via( *attributes, document: )
|
8
|
+
attributes.flatten!
|
9
|
+
document.keys.to_set.includes_all! attributes
|
10
|
+
attributes.each do |attribute|
|
11
|
+
value = document.fetch(attribute)
|
12
|
+
setter = attribute.setter_sym
|
13
|
+
insta = attribute.insta_sym
|
14
|
+
if self.respond_to? setter
|
15
|
+
self.public_send setter, value
|
16
|
+
else
|
17
|
+
self.instance_variable_set insta, value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
def blank?
|
23
|
+
respond_to?(:empty?) ? !!empty? : !self
|
24
|
+
end unless method_defined? :blank?
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
def cli_printable **kwargs
|
27
|
+
String.get_stdout { self.cli_print( **kwargs ) }
|
28
|
+
rescue NoMethodError
|
29
|
+
message = \
|
30
|
+
"`cli_printable` requires `cli_print` on child class"
|
31
|
+
fail NoMethodError, message
|
32
|
+
end unless method_defined? :cli_printable
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
def present?
|
35
|
+
!blank?
|
36
|
+
end unless method_defined? :present?
|
29
37
|
|
30
|
-
|
38
|
+
def one_of? *collection, mixed: false, allow_unsafe: false
|
39
|
+
nested = collection.first.is_a? Array
|
40
|
+
nested ||= collection.first.is_a? Hash
|
41
|
+
nested ||= collection.first.is_a? Set
|
31
42
|
|
32
|
-
|
33
|
-
|
43
|
+
message = \
|
44
|
+
"Unexpected nested argument. If desired set `allow_unsafe: true`."
|
45
|
+
fail ArgumentError, message if nested unless allow_unsafe
|
34
46
|
|
35
|
-
|
36
|
-
fail ArgumentError, message unless ok
|
47
|
+
return collection.include? self if mixed
|
37
48
|
|
38
|
-
|
39
|
-
|
49
|
+
klass = self.class
|
50
|
+
ok = collection.reject {|s| s.is_a? klass }.blank?
|
40
51
|
|
41
|
-
|
42
|
-
|
52
|
+
message = "Invalid types: #{klass} collection required."
|
53
|
+
fail ArgumentError, message unless ok
|
43
54
|
|
44
|
-
|
45
|
-
|
46
|
-
message = "#{klass} `#{self}` is invalid. Must be one of: #{collection}."
|
47
|
-
fail message
|
48
|
-
end
|
55
|
+
collection.include? self
|
56
|
+
end
|
49
57
|
|
50
|
-
|
51
|
-
|
52
|
-
"Expected `#{klass}` instance, not `#{self.class}`."
|
53
|
-
fail ArgumentError, message unless self.is_a? klass
|
54
|
-
end
|
55
|
-
alias_method :must_be_a!, :is_a!
|
58
|
+
def one_of! *collection, mixed: false
|
59
|
+
return true if self.one_of?( *collection, mixed: mixed )
|
56
60
|
|
61
|
+
klass = self.class
|
62
|
+
collection = collection.stringify_collection grave: true
|
63
|
+
message = "#{klass} `#{self}` is invalid. Must be one of: #{collection}."
|
64
|
+
fail message
|
65
|
+
end
|
66
|
+
|
67
|
+
def is_a! klass
|
68
|
+
message = \
|
69
|
+
"Expected `#{klass}` instance, not `#{self.class}`."
|
70
|
+
fail ArgumentError, message unless self.is_a? klass
|
71
|
+
end
|
72
|
+
alias_method :must_be_a!, :is_a!
|
73
|
+
|
74
|
+
end
|
57
75
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class VV::JSON
|
2
|
+
|
3
|
+
def self.default_max
|
4
|
+
1.mebibyte
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.generate object,
|
8
|
+
maximum_bytes=nil,
|
9
|
+
**kwargs
|
10
|
+
|
11
|
+
max = maximum_bytes || self.default_max
|
12
|
+
|
13
|
+
generator = self.new( max, **kwargs )
|
14
|
+
generator.serialize object
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize maximum_bytes,
|
18
|
+
float_kwargs: nil
|
19
|
+
|
20
|
+
@max = maximum_bytes
|
21
|
+
@response = ""
|
22
|
+
@float_kwargs = float_kwargs || {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def serialize object
|
26
|
+
|
27
|
+
self.check_for_size_failure!
|
28
|
+
|
29
|
+
case object
|
30
|
+
when Hash
|
31
|
+
@response += "{"
|
32
|
+
|
33
|
+
object.each do |key, value|
|
34
|
+
self.serialize! key.to_s
|
35
|
+
@response += ":"
|
36
|
+
|
37
|
+
self.serialize! value
|
38
|
+
@response += ","
|
39
|
+
end
|
40
|
+
|
41
|
+
@response.chomp! ","
|
42
|
+
@response += "}"
|
43
|
+
when Array
|
44
|
+
@response += "["
|
45
|
+
|
46
|
+
object.each do |value|
|
47
|
+
self.serialize! value
|
48
|
+
@response += ","
|
49
|
+
end
|
50
|
+
|
51
|
+
@response.chomp! ","
|
52
|
+
@response += "]"
|
53
|
+
when String
|
54
|
+
self.size_failure! if ( object.size + 2 ) > @max
|
55
|
+
@response += object.to_json
|
56
|
+
when Float
|
57
|
+
@response += object.vv_json( **@float_kwargs )
|
58
|
+
else
|
59
|
+
if object.respond_to? :vv_json
|
60
|
+
@response += object.vv_json
|
61
|
+
else
|
62
|
+
fail "VV::JSON cannot generate JSON for `#{object.class}`."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
self.check_for_size_failure!
|
67
|
+
|
68
|
+
@response
|
69
|
+
end
|
70
|
+
alias_method :serialize!, :serialize
|
71
|
+
|
72
|
+
def default_max
|
73
|
+
self.class.default_max
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_for_size_failure!
|
77
|
+
size_failure! if @response.size > @max
|
78
|
+
end
|
79
|
+
|
80
|
+
def size_failure!
|
81
|
+
if @max == self.default_max
|
82
|
+
fail "VV::JSON generation size exceeds default max of 1 MiB"
|
83
|
+
else
|
84
|
+
fail "VV::JSON generation size exceeds max of `#{@max}` bytes"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/lib/vv/set_methods.rb
CHANGED
@@ -15,6 +15,10 @@ module VV
|
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
+
def vv_json
|
19
|
+
self.to_a.vv_json
|
20
|
+
end
|
21
|
+
|
18
22
|
module SetAndArrayMethods
|
19
23
|
|
20
24
|
def gravify
|
@@ -39,7 +43,7 @@ module VV
|
|
39
43
|
ok_type = other.is_a? Array
|
40
44
|
ok_type ||= other.is_a? Set
|
41
45
|
|
42
|
-
fail TypeError, "Expecting array" unless ok_type
|
46
|
+
fail TypeError, "Expecting array or set" unless ok_type
|
43
47
|
|
44
48
|
( self & other ).one?
|
45
49
|
end
|
@@ -56,7 +60,7 @@ module VV
|
|
56
60
|
ok_type = other.is_a? Array
|
57
61
|
ok_type ||= other.is_a? Set
|
58
62
|
|
59
|
-
fail TypeError, "Expecting array" unless ok_type
|
63
|
+
fail TypeError, "Expecting array or set" unless ok_type
|
60
64
|
( self & other ).any?
|
61
65
|
end
|
62
66
|
alias_method :include_any?, :includes_any?
|
@@ -68,6 +72,37 @@ module VV
|
|
68
72
|
end
|
69
73
|
alias_method :include_any!, :includes_any!
|
70
74
|
|
75
|
+
def includes_all? other
|
76
|
+
ok_type = other.is_a? Array
|
77
|
+
ok_type ||= other.is_a? Set
|
78
|
+
|
79
|
+
fail TypeError, "Expecting array or set" unless ok_type
|
80
|
+
( other.to_set & self ) == other.to_set
|
81
|
+
end
|
82
|
+
alias_method :include_all?, :includes_all?
|
83
|
+
|
84
|
+
def includes_all! other
|
85
|
+
return true if includes_all? other
|
86
|
+
other = other.to_set
|
87
|
+
remaining = other - ( other & self )
|
88
|
+
count = remaining.count
|
89
|
+
|
90
|
+
message = "Collection "
|
91
|
+
including = remaining.first(3).stringify_collection grave: true
|
92
|
+
|
93
|
+
fail "Assertion error" if count < 1
|
94
|
+
|
95
|
+
if count < 4
|
96
|
+
message += "does not include: #{including}."
|
97
|
+
else
|
98
|
+
message += \
|
99
|
+
"does not include #{count} items, including: #{including}."
|
100
|
+
end
|
101
|
+
|
102
|
+
fail message
|
103
|
+
end
|
104
|
+
alias_method :include_all!, :includes_all!
|
105
|
+
|
71
106
|
def stringify_collection grave: false
|
72
107
|
return self.gravify.stringify_collection if grave
|
73
108
|
|
data/lib/vv/string_methods.rb
CHANGED
@@ -323,11 +323,15 @@ module VV
|
|
323
323
|
raise RuntimeError, message
|
324
324
|
end
|
325
325
|
|
326
|
+
def vv_json
|
327
|
+
VV::JSON.generate self
|
328
|
+
end
|
329
|
+
|
326
330
|
def parse notation: :json
|
327
331
|
message = "Only JSON support at this time."
|
328
332
|
fail NotImplementedError, message unless notation == :json
|
329
333
|
|
330
|
-
JSON.parse self
|
334
|
+
::JSON.parse self
|
331
335
|
end
|
332
336
|
|
333
337
|
def parse_json
|
@@ -436,6 +440,15 @@ module VV
|
|
436
440
|
self.insta.to_sym
|
437
441
|
end
|
438
442
|
|
443
|
+
def setter
|
444
|
+
return self if self.ends_with?(String.equals_sign)
|
445
|
+
"#{self}="
|
446
|
+
end
|
447
|
+
|
448
|
+
def setter_sym
|
449
|
+
self.setter.to_sym
|
450
|
+
end
|
451
|
+
|
439
452
|
def to position
|
440
453
|
self[0..position]
|
441
454
|
end
|
data/lib/vv/symbol_methods.rb
CHANGED
@@ -11,6 +11,10 @@ module VV
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
def vv_json
|
15
|
+
self.to_s.vv_json
|
16
|
+
end
|
17
|
+
|
14
18
|
def insta
|
15
19
|
self.to_s.insta
|
16
20
|
end
|
@@ -19,6 +23,14 @@ module VV
|
|
19
23
|
self.to_s.insta_sym
|
20
24
|
end
|
21
25
|
|
26
|
+
def setter
|
27
|
+
self.to_s.setter
|
28
|
+
end
|
29
|
+
|
30
|
+
def setter_sym
|
31
|
+
self.to_s.setter_sym
|
32
|
+
end
|
33
|
+
|
22
34
|
def plural? *args, **kwargs
|
23
35
|
self.to_s.plural?( *args, **kwargs )
|
24
36
|
end
|
data/lib/vv/utility/automate.rb
CHANGED
@@ -49,8 +49,9 @@ module VV
|
|
49
49
|
puts "++ - minor increment"
|
50
50
|
puts "+++ - major increment"
|
51
51
|
puts
|
52
|
-
puts "x.y.z
|
53
|
-
puts "reset
|
52
|
+
puts "x.y.z - to set version explicitly"
|
53
|
+
puts "reset - to revert to version in git"
|
54
|
+
puts "commit - to commit the version change"
|
54
55
|
puts
|
55
56
|
exit
|
56
57
|
end
|
data/lib/vv/version.rb
CHANGED
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.15
|
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-03-
|
11
|
+
date: 2019-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/vv/object_methods.rb
|
78
78
|
- lib/vv/random_methods.rb
|
79
79
|
- lib/vv/readline_methods.rb
|
80
|
+
- lib/vv/serialization/json.rb
|
80
81
|
- lib/vv/set_methods.rb
|
81
82
|
- lib/vv/string_methods.rb
|
82
83
|
- lib/vv/style/bold.rb
|
@@ -108,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
|
-
|
112
|
-
rubygems_version: 2.7.7
|
112
|
+
rubygems_version: 3.0.3
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Make ruby very v
|