cliutils 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +5 -0
- data/lib/cliutils/configurator.rb +14 -1
- data/lib/cliutils/constants.rb +1 -1
- data/lib/cliutils/ext/hash_extensions.rb +7 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdf67aa4209a6fcb36db63a0b84313c539c7d2f3
|
4
|
+
data.tar.gz: c180f98c6075639be2c28ab114ea2b331abaf111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa8a999f929b9bd694983ce2e4f2e6430ec1c8c21bb03b715d1fe8215e40cccc4c55df1e7d95ac968fe4099fd1ab250d078eb909d67580056980ed584207c0af
|
7
|
+
data.tar.gz: 41f09163ab9109af87277c860cdd0955d1382bef320b151206882e31074af675098de80ba3139325cea8de81b5aed41f288231f07d87a5a7ee225492c52ecc78
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'fileutils'
|
1
2
|
require 'yaml'
|
2
3
|
|
3
4
|
module CLIUtils
|
@@ -55,6 +56,18 @@ module CLIUtils
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
59
|
+
# Convenience method to backup the configuration file
|
60
|
+
# in the same directory that the original inhabits.
|
61
|
+
# @return [String] The backed-up filepath
|
62
|
+
def backup
|
63
|
+
backup_path = ''
|
64
|
+
unless @config_path.nil? || @config_path.empty?
|
65
|
+
backup_path = "#{ @config_path }-#{ Time.now.to_i }"
|
66
|
+
FileUtils.cp(@config_path, backup_path)
|
67
|
+
end
|
68
|
+
backup_path
|
69
|
+
end
|
70
|
+
|
58
71
|
# Compares the current version (if it exists) to
|
59
72
|
# the last version that needed a configuration
|
60
73
|
# change (if it exists). Assuming they exist and
|
@@ -97,7 +110,7 @@ module CLIUtils
|
|
97
110
|
# Hook that fires when a non-existent method is called.
|
98
111
|
# Allows this module to return data from the config
|
99
112
|
# Hash when given a method name that matches a key.
|
100
|
-
# @return [Hash]
|
113
|
+
# @return [Hash] The hash with the method's name as key
|
101
114
|
def method_missing(name, *args, &block)
|
102
115
|
@data[name.to_sym] || @data.merge!(name.to_sym => {})
|
103
116
|
end
|
data/lib/cliutils/constants.rb
CHANGED
@@ -5,7 +5,7 @@ class Hash
|
|
5
5
|
# Deep merges a hash into the current one.
|
6
6
|
# @param [Hash] other_hash The hash to merge in
|
7
7
|
# @yield &block
|
8
|
-
# @return [Hash]
|
8
|
+
# @return [Hash] The original Hash
|
9
9
|
def deep_merge!(other_hash, &block)
|
10
10
|
other_hash.each_pair do |k, v|
|
11
11
|
tv = self[k]
|
@@ -20,28 +20,28 @@ class Hash
|
|
20
20
|
|
21
21
|
# Recursively turns all Hash keys into strings and
|
22
22
|
# returns the new Hash.
|
23
|
-
# @return [Hash]
|
23
|
+
# @return [Hash] A new copy of the original Hash
|
24
24
|
def deep_stringify_keys
|
25
25
|
deep_transform_keys { |key| key.to_s }
|
26
26
|
end
|
27
27
|
|
28
28
|
# Same as deep_stringify_keys, but destructively
|
29
29
|
# alters the original Hash.
|
30
|
-
# @return [Hash]
|
30
|
+
# @return [Hash] The original Hash
|
31
31
|
def deep_stringify_keys!
|
32
32
|
deep_transform_keys! { |key| key.to_s }
|
33
33
|
end
|
34
34
|
|
35
35
|
# Recursively turns all Hash keys into symbols and
|
36
36
|
# returns the new Hash.
|
37
|
-
# @return [Hash]
|
37
|
+
# @return [Hash] A new copy of the original Hash
|
38
38
|
def deep_symbolize_keys
|
39
39
|
deep_transform_keys { |key| key.to_sym rescue key }
|
40
40
|
end
|
41
41
|
|
42
42
|
# Same as deep_symbolize_keys, but destructively
|
43
43
|
# alters the original Hash.
|
44
|
-
# @return [Hash]
|
44
|
+
# @return [Hash] The original Hash
|
45
45
|
def deep_symbolize_keys!
|
46
46
|
deep_transform_keys! { |key| key.to_sym rescue key }
|
47
47
|
end
|
@@ -49,7 +49,7 @@ class Hash
|
|
49
49
|
# Generic method to perform recursive operations on a
|
50
50
|
# Hash.
|
51
51
|
# @yield &block
|
52
|
-
# @return [Hash]
|
52
|
+
# @return [Hash] A new copy of the original Hash
|
53
53
|
def deep_transform_keys(&block)
|
54
54
|
_deep_transform_keys_in_object(self, &block)
|
55
55
|
end
|
@@ -57,7 +57,7 @@ class Hash
|
|
57
57
|
# Same as deep_transform_keys, but destructively
|
58
58
|
# alters the original Hash.
|
59
59
|
# @yield &block
|
60
|
-
# @return [Hash]
|
60
|
+
# @return [Hash] The original Hash
|
61
61
|
def deep_transform_keys!(&block)
|
62
62
|
_deep_transform_keys_in_object!(self, &block)
|
63
63
|
end
|