methadone 1.6.0 → 1.7.0

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: 28edf03f317826eca04da77d8a6fb3bf4fb0c977
4
- data.tar.gz: 64b4d8b287ec915faee422425d9054ef79f95b73
3
+ metadata.gz: 6f6cada4890a57e4aaee044b291ed1a345e0cdc0
4
+ data.tar.gz: 3c2616c59e9a043980fa2d690934ba6877da0d00
5
5
  SHA512:
6
- metadata.gz: 1e4c6b2c4b41d4f25b6d60c1dc8a2975da51a39cc62bb8073457b61a6c306043b177705f75f10c06cb62452a779730db5263616c7d9e35b5ae6886afe29d8229
7
- data.tar.gz: 1a0e5f3bc306390de60e25f4a248dc5343e97362fdc4afd7a17a7c854069520af02d480287743a54eb3a7ff358174344d8ed0d718855e3aa5c708997ee1471bc
6
+ metadata.gz: c5f40dd8ff1d8903c4447529b663c52c27063ccf718a8ece6937e6011ce53669840fb14e65c2094b8e92e460bf2156b1e1f15ed9ddc3c080e445d73edca8b0dc
7
+ data.tar.gz: 1c0d003dcf3cdc66937b8bfd3979a2b749e7b3fa09acdbc2a5a9ee5428e371834b243bcc38b23c3da100e1000b280e50db1e94679fe26bb4ede1d60b541bfc8b
data/README.rdoc CHANGED
@@ -32,15 +32,12 @@ http://a1.mzstatic.com/us/r30/Publication/v4/2c/f7/90/2cf7902f-f709-9125-c73d-87
32
32
  == Platforms
33
33
 
34
34
  * The build runs on Travis for:
35
- * MRI Ruby 1.8.7
36
35
  * MRI Ruby 1.9.2
37
36
  * MRI Ruby 1.9.3
38
- * RBX
39
- * REE
37
+ * MRI Ruby 2.0.0
38
+ * MRI Ruby 2.1.0
40
39
  * JRuby in both 1.8 and 1.9 mode
41
40
 
42
- It should work on 2.0.0 but there's a weird bundler issue where some of the aruba tests fail in odd ways.
43
-
44
41
  == Bootstrapping a new CLI App
45
42
 
46
43
  The +methadone+ command-line app will bootstrap a new command-line app, setting up a proper gem structure, unit tests, and cucumber-based tests with aruba:
@@ -129,7 +126,7 @@ Methadone::CLILogger is designed to handle this. It's a proper subclass of Ruby
129
126
  See {CLILogger's rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogger.html] and then {CLILogging's}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogging.html] for more.
130
127
 
131
128
 
132
- Currently, there are classes the assist in directing output logger-style to the right place; basically ensuring that errors go to +STDERR+ and everything else goes to +STDOUT+. All of this is, of course, configurable
129
+ Currently, there are classes that assist in directing output logger-style to the right place; basically ensuring that errors go to +STDERR+ and everything else goes to +STDOUT+. All of this is, of course, configurable
133
130
 
134
131
  == Cucumber Steps
135
132
 
@@ -74,7 +74,11 @@ module Methadone
74
74
  }
75
75
 
76
76
  # Call this *if* you've included Methadone::Main to set up a <tt>--log-level</tt> option for your app
77
- # that will allow the user to configure the logging level.
77
+ # that will allow the user to configure the logging level. You can pass an optional hash with
78
+ # <tt>:toggle_debug_on_signal => <SIGNAME></tt> to enable runtime toggling of the log level by sending the
79
+ # signal <tt><SIGNAME></tt> to your app
80
+ #
81
+ # +args+:: optional hash
78
82
  #
79
83
  # Example:
80
84
  #
@@ -86,12 +90,48 @@ module Methadone
86
90
  #
87
91
  # go!
88
92
  #
89
- def use_log_level_option
93
+ # Example with runtime toggling:
94
+ #
95
+ #
96
+ # main do
97
+ # # your app
98
+ # end
99
+ #
100
+ # use_log_level_option :toggle_debug_on_signal => 'USR1'
101
+ #
102
+ # go!
103
+ def use_log_level_option(args = {})
90
104
  on("--log-level LEVEL",LOG_LEVELS,'Set the logging level',
91
105
  '(' + LOG_LEVELS.keys.join('|') + ')',
92
106
  '(Default: info)') do |level|
93
107
  @log_level = level
108
+ @log_level_original = level
109
+ @log_level_toggled = false
94
110
  logger.level = level
111
+
112
+ setup_toggle_trap(args[:toggle_debug_on_signal])
113
+ end
114
+ end
115
+
116
+ private
117
+
118
+ # Call this to toggle the log level between <tt>debug</tt> and its initial value
119
+ def toggle_log_level
120
+ @log_level_original = logger.level unless @log_level_toggled
121
+ logger.level = if @log_level_toggled
122
+ @log_level_original
123
+ else
124
+ LOG_LEVELS['debug']
125
+ end
126
+ @log_level_toggled = !@log_level_toggled
127
+ @log_level = logger.level
128
+ end
129
+
130
+ def setup_toggle_trap(signal)
131
+ if signal
132
+ Signal.trap(signal) do
133
+ toggle_log_level
134
+ end
95
135
  end
96
136
  end
97
137
  end
@@ -18,17 +18,17 @@ module Methadone
18
18
  # <tt>[2]</tt>:: A Process::Status-like objects that responds to <tt>exitstatus</tt> which returns
19
19
  # the exit code of the command (e.g. 0 for success).
20
20
  def run_command(command)
21
- subclass_must_impelment!
21
+ subclass_must_implement!
22
22
  end
23
23
 
24
24
  # Returns the class that, if caught by calling #run_command, represents the underlying command
25
25
  # not existing. For example, in MRI Ruby, if you try to execute a non-existent command,
26
26
  # you get a Errno::ENOENT.
27
27
  def exception_meaning_command_not_found
28
- subclass_must_impelment!
28
+ subclass_must_implement!
29
29
  end
30
30
  protected
31
- def subclass_must_impelment!; raise "subclass must implement"; end
31
+ def subclass_must_implement!; raise "subclass must implement"; end
32
32
  end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Methadone #:nodoc:
2
- VERSION = "1.6.0" #:nodoc:
2
+ VERSION = "1.7.0" #:nodoc:
3
3
  end
@@ -37,7 +37,7 @@ class App
37
37
 
38
38
  version <%= module_name %>::VERSION
39
39
 
40
- use_log_level_option
40
+ use_log_level_option :toggle_debug_on_signal => 'USR1'
41
41
 
42
42
  go!
43
43
  end
@@ -5,6 +5,8 @@ require 'stringio'
5
5
  class TestCLILogging < BaseTest
6
6
  include Methadone
7
7
 
8
+ SLEEP_TIME = 0.1
9
+
8
10
  def setup
9
11
  @blank_format = proc do |severity,datetime,progname,msg|
10
12
  msg + "\n"
@@ -122,11 +124,61 @@ class TestCLILogging < BaseTest
122
124
  }
123
125
  end
124
126
 
127
+
128
+ test_that "when we enable runtime log level toggling, it toggles the log level on receiving the set signal" do
129
+ Given {
130
+ @app = MyAppThatActsLikeItUsesMain.new
131
+ @app.call_use_log_level_option( :toggle_debug_on_signal => 'USR2' )
132
+ @level = Logger::INFO
133
+ @app.use_option(@level)
134
+ }
135
+ When {
136
+ send_signal_and_wait_a_moment('USR2')
137
+ }
138
+ Then {
139
+ @app.logger.level.should == Logger::DEBUG
140
+ }
141
+ end
142
+
143
+ test_that "when we toggle the log level and change the logger, the new logger has also it's log level increased" do
144
+ Given {
145
+ @app = MyAppThatActsLikeItUsesMain.new
146
+ @app.call_use_log_level_option( :toggle_debug_on_signal => 'USR2' )
147
+ @level = Logger::INFO
148
+ @app.use_option(@level)
149
+ }
150
+ When {
151
+ send_signal_and_wait_a_moment('USR2')
152
+ @other_logger = OpenStruct.new
153
+ @app.change_logger(@other_logger)
154
+ }
155
+ Then {
156
+ @other_logger.level.should == Logger::DEBUG
157
+ }
158
+ end
159
+
160
+ test_that "when we enable runtime log level toggling and send the signal twice, the original log level is restored" do
161
+ Given {
162
+ @app = MyAppThatActsLikeItUsesMain.new
163
+ @app.call_use_log_level_option( :toggle_debug_on_signal => 'USR2' )
164
+ @level = Logger::INFO
165
+ @app.use_option(@level)
166
+ }
167
+ When {
168
+ send_signal_and_wait_a_moment('USR2')
169
+ send_signal_and_wait_a_moment('USR2')
170
+ }
171
+ Then {
172
+ @app.logger.level.should == Logger::INFO
173
+ }
174
+ end
175
+
176
+
125
177
  class MyAppThatActsLikeItUsesMain
126
178
  include Methadone::CLILogging
127
179
 
128
- def call_use_log_level_option
129
- use_log_level_option
180
+ def call_use_log_level_option(args = {})
181
+ use_log_level_option(args)
130
182
  end
131
183
 
132
184
  def use_option(level)
@@ -183,4 +235,9 @@ class TestCLILogging < BaseTest
183
235
 
184
236
  def logger_id; logger.object_id; end
185
237
  end
238
+
239
+ def send_signal_and_wait_a_moment(signal)
240
+ Process.kill(signal, $$)
241
+ sleep(SLEEP_TIME) # call sleep to give the trap handler a chance to kick in
242
+ end
186
243
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: methadone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - davetron5000
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-17 00:00:00.000000000 Z
11
+ date: 2014-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler