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 +4 -4
- data/Gemfile.lock +1 -1
- data/HISTORY.md +4 -0
- data/README.md +6 -4
- data/lib/cliutils/logger-delegator.rb +8 -5
- data/lib/cliutils/messenging.rb +1 -1
- data/lib/cliutils/prefs.rb +1 -1
- data/lib/cliutils/version.rb +1 -1
- data/test/messenging_test.rb +2 -2
- 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: 96c4a2208dc32603d60a3d1615cbcee89e35089f
|
4
|
+
data.tar.gz: 74a8b7774dc1b13e054de3449e2fdf8666648673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e29a35f2889f09151ff12dcd1db686f8b984a5fa84eb8d93e2e54cbdf3975afa20e71c444dd549a6f877ee07bc9553d708f36affa1963f681a0d1bfb41e7c942
|
7
|
+
data.tar.gz: d9c9efd319ad362fa145c8abee217898fccb46f175fa3d5a120a922a1c714c5e95e11162e99bd80cb653d881e840d9cfac28f0fbfe902b5077952dbc2d9dc923
|
data/Gemfile.lock
CHANGED
data/HISTORY.md
CHANGED
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
|
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
|
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(
|
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
|
-
|
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.
|
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(
|
40
|
-
@targets.
|
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
|
data/lib/cliutils/messenging.rb
CHANGED
data/lib/cliutils/prefs.rb
CHANGED
data/lib/cliutils/version.rb
CHANGED
data/test/messenging_test.rb
CHANGED
@@ -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(
|
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.
|
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-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|