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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b754284592bdb559d6b8ed5715d7d23844e77198
4
- data.tar.gz: 71596185e2543a8c8896926d05f444fe041c5510
3
+ metadata.gz: 724a3b34821219924e9ef1b69acd822df4c09c50
4
+ data.tar.gz: cb71d1de33c349b0fd7f41eff987fa1fcfa07ece
5
5
  SHA512:
6
- metadata.gz: d9171c3888852dec708db91025b5be0804328945a624964540985f6234f197e73ed1bec1df929e28dcb0c68ed1deab6fd7bd9f11a14fd0bba10cfb2694de73c7
7
- data.tar.gz: bdbc9330596c23680f26081b9329f86df278bbdbedf206805a46d298b40497e9ed1d531b940b04c05e4464339689fea9a359b08160cecf97e644dc701c0b2d72
6
+ metadata.gz: 8842f7bf8ce1f372a7e8fd76c3b98d3d89c6ce1f977fe85c53a750cb2e2ac2e71e6a7f35273f7feeaaba85927706828e9845e83ec4f829991da1506d60bc496e
7
+ data.tar.gz: 688a45b787a2ae8b98dcfe2c05fdba5eea23f56c6a59430b97bbce6be259e77d9216cb7b09109f792daf9d06c21e67da37d0cca29a59be03fc9d5c44393e68d0
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.2.2 (2014-05-04)
2
+
3
+ * Added dot-notation syntax for Hash extensions
4
+
1
5
  # 2.2.1 (2014-05-04)
2
6
 
3
7
  * Easier Configuration path setting
data/lib/cliutils.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'cliutils/ext/hash_extensions'
2
2
  require 'cliutils/ext/logger_extensions'
3
3
  require 'cliutils/ext/string_extensions'
4
-
5
4
  require 'cliutils/constants'
6
5
  require 'cliutils/pretty_io'
7
6
  require 'cliutils/configurator'
@@ -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] || @data.merge!(name.to_sym => {})
118
+ @data[name.to_sym] ||= {}
116
119
  end
117
120
 
118
121
  # Clears the configuration data.
@@ -8,5 +8,5 @@ module CLIUtils
8
8
  SUMMARY = 'Sugary goodness for Ruby CLI apps.'
9
9
 
10
10
  # The current version of the gem
11
- VERSION = '2.2.1'
11
+ VERSION = '2.2.2'
12
12
  end
@@ -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' ? oldval.deep_merge(newval) : newval
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
@@ -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.1
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-04 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler