k_util 0.0.12 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/k_util.rb +2 -1
- data/lib/k_util/data/instance_variables_to_h.rb +21 -0
- data/lib/k_util/data_helper.rb +21 -1
- data/lib/k_util/file_helper.rb +6 -1
- data/lib/k_util/version.rb +5 -5
- 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: b521dc46323b33d082574de08feba5ef83f167b0feea433d902217e62c934557
|
4
|
+
data.tar.gz: 6f4f9aca566de81776cdbe6496772034a13f14a973297f738a9a6ecf6856f3eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf2a72c8bcb86ca6ac4d1e3b286150bf175c5e95018eef603d32fecd010b490e3f266944642cbe6ad9f66dbedcccf30d8c7b4824ff6feb661ad35f257969965e
|
7
|
+
data.tar.gz: da68fc44fe300cb6130a4e25a31a57431f47d01152683b76f35d5b16a04d34e121d9d66bcc8971d5e1f70e6fd99d588c20b19f815dc1aa9130b951189a88c8a7
|
data/lib/k_util.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'k_util/version'
|
4
4
|
require 'k_util/console_helper'
|
5
|
+
require 'k_util/data/instance_variables_to_h'
|
5
6
|
require 'k_util/data_helper'
|
6
7
|
require 'k_util/file_helper'
|
7
8
|
|
@@ -25,5 +26,5 @@ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
|
|
25
26
|
namespace = 'KUtil::Version'
|
26
27
|
file_path = $LOADED_FEATURES.find { |f| f.include?('k_util/version') }
|
27
28
|
version = KUtil::VERSION.ljust(9)
|
28
|
-
puts "#{namespace.ljust(
|
29
|
+
puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
|
29
30
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Provide data object helper functions
|
4
|
+
module KUtil
|
5
|
+
module Data
|
6
|
+
# Helper methods attached to the namespace for working with Data
|
7
|
+
module InstanceVariablesToH
|
8
|
+
def to_h
|
9
|
+
hash = {}
|
10
|
+
instance_variables.each do |var|
|
11
|
+
value = instance_variable_get(var)
|
12
|
+
|
13
|
+
value = KUtil.data.to_hash(value) if KUtil.data.hash_convertible?(value)
|
14
|
+
|
15
|
+
hash[var.to_s.delete('@')] = value
|
16
|
+
end
|
17
|
+
hash
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/k_util/data_helper.rb
CHANGED
@@ -39,7 +39,7 @@ module KUtil
|
|
39
39
|
when Array
|
40
40
|
# No test yet
|
41
41
|
values = value.map do |v|
|
42
|
-
v.is_a?(OpenStruct) || v.is_a?(Struct) || v.is_a?(Hash) ?
|
42
|
+
v.is_a?(OpenStruct) || v.is_a?(Struct) || v.is_a?(Hash) ? to_hash(v) : v
|
43
43
|
end
|
44
44
|
hash[key] = values
|
45
45
|
else
|
@@ -54,5 +54,25 @@ module KUtil
|
|
54
54
|
|
55
55
|
value.is_a?(Symbol) ? value.to_s : value
|
56
56
|
end
|
57
|
+
|
58
|
+
# Add if needed
|
59
|
+
# # Is the value a basic (aka primitive) type
|
60
|
+
# def basic_type?(value)
|
61
|
+
# value.is_a?(String) ||
|
62
|
+
# value.is_a?(Symbol) ||
|
63
|
+
# value.is_a?(FalseClass) ||
|
64
|
+
# value.is_a?(TrueClass) ||
|
65
|
+
# value.is_a?(Integer) ||
|
66
|
+
# value.is_a?(Float)
|
67
|
+
# end
|
68
|
+
|
69
|
+
# Is the value a complex container type, but not a regular class.
|
70
|
+
def hash_convertible?(value)
|
71
|
+
value.is_a?(Array) ||
|
72
|
+
value.is_a?(Hash) ||
|
73
|
+
value.is_a?(Struct) ||
|
74
|
+
value.is_a?(OpenStruct) ||
|
75
|
+
value.respond_to?(:to_h)
|
76
|
+
end
|
57
77
|
end
|
58
78
|
end
|
data/lib/k_util/file_helper.rb
CHANGED
@@ -14,12 +14,17 @@ module KUtil
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def home?(path)
|
18
18
|
path.start_with?('~/')
|
19
19
|
end
|
20
20
|
|
21
21
|
def pathname_absolute?(pathname)
|
22
22
|
Pathname.new(pathname).absolute?
|
23
23
|
end
|
24
|
+
alias absolute? pathname_absolute?
|
25
|
+
|
26
|
+
def home_or_absolute?(path)
|
27
|
+
home?(path) || absolute?(path)
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
data/lib/k_util/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module KUtil
|
4
|
-
VERSION = '0.0.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KUtil
|
4
|
+
VERSION = '0.0.15'
|
5
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_util
|
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
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " KUtil provides simple utility methods, such as file helpers, data
|
14
14
|
object helpers and more.\n"
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- k_util.gemspec
|
41
41
|
- lib/k_util.rb
|
42
42
|
- lib/k_util/console_helper.rb
|
43
|
+
- lib/k_util/data/instance_variables_to_h.rb
|
43
44
|
- lib/k_util/data_helper.rb
|
44
45
|
- lib/k_util/file_helper.rb
|
45
46
|
- lib/k_util/version.rb
|