cliutils 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8839468d53bb07c10d7e1d3bbda3fce0d65d9f4c
4
- data.tar.gz: 7bea2c8039d87cbb73660649f42350501a84efe6
3
+ metadata.gz: 96c4a2208dc32603d60a3d1615cbcee89e35089f
4
+ data.tar.gz: 74a8b7774dc1b13e054de3449e2fdf8666648673
5
5
  SHA512:
6
- metadata.gz: 67a30a0cc57dbc88a773262a2ac543424b1ff1dd7952bf7ecf7419e2c93a74fce2cb8d6a1b8aa45bfb1b11f801f336bf0c646d5b871e31cb0dc71730cca4cf61
7
- data.tar.gz: c10b1b10d0f32a72a389a513727c3c9e1c3da504fd3981a1896dfce648d0b3d036e6c46cc86e8216204663523dca8dfbae93e8ed5db94219c05e62af2c997e38
6
+ metadata.gz: e29a35f2889f09151ff12dcd1db686f8b984a5fa84eb8d93e2e54cbdf3975afa20e71c444dd549a6f877ee07bc9553d708f36affa1963f681a0d1bfb41e7c942
7
+ data.tar.gz: d9c9efd319ad362fa145c8abee217898fccb46f175fa3d5a120a922a1c714c5e95e11162e99bd80cb653d881e840d9cfac28f0fbfe902b5077952dbc2d9dc923
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cliutils (1.0.6)
4
+ cliutils (1.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.7 (2014-03-30)
2
+
3
+ * Modified Messenging targets to be a Hash for easier lookup/deletion
4
+
1
5
  # 1.0.6 (2014-03-30)
2
6
 
3
7
  * Added convenience logging constant to Configuration
data/README.md CHANGED
@@ -176,17 +176,19 @@ Often, it's desirable to log messages as they appear to your user. `messenging`
176
176
  For instance, let's say you wanted to log a few messages to both your user's STDOUT and to `file.txt`:
177
177
 
178
178
  ```Ruby
179
- file_logger = Logger.new('file.txt')
180
-
181
179
  messenger.info('This should only appear in STDOUT.')
182
180
 
183
- messenger.attach(file_logger)
181
+ #messenger.attach takes a Hash of string/symbol keys
182
+ # and Logger values (so you can refer to them later on).
183
+ messenger.attach(MY\_FILE\_LOGGER: Logger.new('file.txt'))
184
184
 
185
185
  messenger.warn('This warning should appear in STDOUT and file.txt')
186
186
  messenger.error('This error should appear in STDOUT and file.txt')
187
187
  messenger.debug('This debug message should only appear in file.txt')
188
188
 
189
- messenger.detach(file_logger)
189
+ # messenger.detach takes the string/symbol key
190
+ # defined earlier.
191
+ messenger.detach(:MY\_FILE\_LOGGER)
190
192
 
191
193
  messenger.section('This section message should appear only in STDOUT')
192
194
  ```
@@ -10,7 +10,7 @@ module CLIUtils
10
10
  # Initializes and creates methods for the passed targets.
11
11
  # @param [Logger] targets The endpoints to delegate to
12
12
  # @return [void]
13
- def initialize(*targets)
13
+ def initialize(targets)
14
14
  @targets = targets
15
15
  LoggerDelegator.delegate
16
16
  end
@@ -19,7 +19,8 @@ module CLIUtils
19
19
  # @param [Logger] target The targets to delegate to
20
20
  # @return [void]
21
21
  def attach(target)
22
- @targets << target
22
+ fail "Cannot add invalid target: #{ target }" unless target.is_a?(Hash)
23
+ @targets.merge!(target)
23
24
  LoggerDelegator.delegate
24
25
  end
25
26
 
@@ -29,15 +30,17 @@ module CLIUtils
29
30
  def self.delegate
30
31
  %w(log debug info warn error section success).each do |m|
31
32
  define_method(m) do |*args|
32
- @targets.map { |t| t.send(m, *args) }
33
+ @targets.each_value { |v| v.send(m, *args) }
33
34
  end
34
35
  end
35
36
  end
36
37
 
37
38
  # Detaches a delegation target.
39
+ # @param [<String, Symbol>] target_name The target to remove
38
40
  # @return [void]
39
- def detach(target)
40
- @targets.delete(target)
41
+ def detach(target_name)
42
+ fail "Cannot delete invalid target: #{ target_name }" unless @targets.key?(target_name)
43
+ @targets.delete(target_name)
41
44
  LoggerDelegator.delegate
42
45
  end
43
46
  end
@@ -22,7 +22,7 @@ module CLIUtils
22
22
  send(severity.downcase, msg)
23
23
  end
24
24
 
25
- LoggerDelegator.new(stdout_logger)
25
+ LoggerDelegator.new(STDOUT: stdout_logger)
26
26
  end
27
27
 
28
28
  # Singleton method to return (or initialize, if needed)
@@ -32,7 +32,7 @@ module CLIUtils
32
32
  prompts = YAML::load_file(data)
33
33
  @prompts.deep_merge!(prompts).deep_symbolize_keys!
34
34
  else
35
- fail "Invalid configuration file: #{ yaml_path }"
35
+ fail "Invalid configuration file: #{ data }"
36
36
  end
37
37
  when Hash
38
38
  @config_path = nil
@@ -1,4 +1,4 @@
1
1
  module CLIUtils
2
2
  # The current version of the gem
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
@@ -39,10 +39,10 @@ class TestMessenging < Test::Unit::TestCase
39
39
  "#{ severity }: #{ msg }\n"
40
40
  end
41
41
 
42
- messenger.attach(file_logger)
42
+ messenger.attach(FILE: file_logger)
43
43
  messenger.send(:info, 'Info test')
44
44
  messenger.send(:error, 'Error test')
45
- messenger.detach(file_logger)
45
+ messenger.detach(:FILE)
46
46
  messenger.send(:warn, 'Warn test')
47
47
 
48
48
  File.open(@file1path, 'r') do |f|
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: 1.0.6
4
+ version: 1.0.7
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-03-30 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler