cliutils 2.2.1 → 2.2.2
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/HISTORY.md +4 -0
- data/lib/cliutils.rb +0 -1
- data/lib/cliutils/configurator.rb +4 -1
- data/lib/cliutils/constants.rb +1 -1
- data/lib/cliutils/ext/hash_extensions.rb +17 -1
- data/spec/configurator_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 724a3b34821219924e9ef1b69acd822df4c09c50
|
4
|
+
data.tar.gz: cb71d1de33c349b0fd7f41eff987fa1fcfa07ece
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8842f7bf8ce1f372a7e8fd76c3b98d3d89c6ce1f977fe85c53a750cb2e2ac2e71e6a7f35273f7feeaaba85927706828e9845e83ec4f829991da1506d60bc496e
|
7
|
+
data.tar.gz: 688a45b787a2ae8b98dcfe2c05fdba5eea23f56c6a59430b97bbce6be259e77d9216cb7b09109f792daf9d06c21e67da37d0cca29a59be03fc9d5c44393e68d0
|
data/HISTORY.md
CHANGED
data/lib/cliutils.rb
CHANGED
@@ -110,9 +110,12 @@ module CLIUtils
|
|
110
110
|
# Hook that fires when a non-existent method is called.
|
111
111
|
# Allows this module to return data from the config
|
112
112
|
# Hash when given a method name that matches a key.
|
113
|
+
# @param [<String, Symbol>] name The name of the method
|
114
|
+
# @param [Array] args The arguments
|
115
|
+
# @yield if a block is passed
|
113
116
|
# @return [Hash] The hash with the method's name as key
|
114
117
|
def method_missing(name, *args, &block)
|
115
|
-
@data[name.to_sym]
|
118
|
+
@data[name.to_sym] ||= {}
|
116
119
|
end
|
117
120
|
|
118
121
|
# Clears the configuration data.
|
data/lib/cliutils/constants.rb
CHANGED
@@ -10,7 +10,8 @@ class Hash
|
|
10
10
|
self.merge(other_hash) do |key, oldval, newval|
|
11
11
|
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
|
12
12
|
newval = newval.to_hash if newval.respond_to?(:to_hash)
|
13
|
-
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ?
|
13
|
+
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ?
|
14
|
+
oldval.deep_merge(newval) : newval
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -66,6 +67,21 @@ class Hash
|
|
66
67
|
_deep_transform_keys_in_object!(self, &block)
|
67
68
|
end
|
68
69
|
|
70
|
+
# Allows for dot-notation getting/setting within
|
71
|
+
# a Hash.
|
72
|
+
# http://ceronio.net/2012/01/javascript-style-object-value-assignment-in-ruby/
|
73
|
+
# @param [<String, Symbol>] meth The method name
|
74
|
+
# @param [Array] args Any passed arguments
|
75
|
+
# @yield if a block is passed
|
76
|
+
def method_missing(meth, *args, &block)
|
77
|
+
meth_name = meth.to_s
|
78
|
+
if meth_name[-1,1] == '='
|
79
|
+
self[meth_name[0..-2].to_sym] = args[0]
|
80
|
+
else
|
81
|
+
self[meth] || self[meth_name]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
69
85
|
# Recursively searches a hash for the passed
|
70
86
|
# key and returns the value (if there is one).
|
71
87
|
# http://stackoverflow.com/a/2239847/327179
|
data/spec/configurator_spec.rb
CHANGED
@@ -53,6 +53,12 @@ describe CLIUtils::Configuration do
|
|
53
53
|
config.data[:test].merge!(name: 'Bob')
|
54
54
|
expect(config.data[:test][:name]).to eq('Bob')
|
55
55
|
expect(config.test[:name]).to eq('Bob')
|
56
|
+
expect(config.test.name).to eq('Bob')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'allows data setting via hash or magic methods' do
|
60
|
+
config.test.name = 'Aaron'
|
61
|
+
expect(config.data[:test][:name]).to eq('Aaron')
|
56
62
|
end
|
57
63
|
|
58
64
|
it 'resets the entire data collection' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cliutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Bach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|