cliutils 2.2.2 → 2.2.3

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: 724a3b34821219924e9ef1b69acd822df4c09c50
4
- data.tar.gz: cb71d1de33c349b0fd7f41eff987fa1fcfa07ece
3
+ metadata.gz: 74dcd411f3846055d59b17657ce5fc4664abca70
4
+ data.tar.gz: 85d369daafb30cf5f5a0110b783928a00ebd4f90
5
5
  SHA512:
6
- metadata.gz: 8842f7bf8ce1f372a7e8fd76c3b98d3d89c6ce1f977fe85c53a750cb2e2ac2e71e6a7f35273f7feeaaba85927706828e9845e83ec4f829991da1506d60bc496e
7
- data.tar.gz: 688a45b787a2ae8b98dcfe2c05fdba5eea23f56c6a59430b97bbce6be259e77d9216cb7b09109f792daf9d06c21e67da37d0cca29a59be03fc9d5c44393e68d0
6
+ metadata.gz: 99aeb8fcb77f0cfdc5bad45727ad37861bb454e5e8442d2fd8c6fd3c0eefacd3f0229da51dcbf1a93f8b1dbb3eb1c419de6af15ed422d149810bf2737a23862b
7
+ data.tar.gz: 829b1e7e5275f456effead9406e9d04241b321d40791d77c37b5715e9ee4ea031ed30e81d6352533a68109fcb35dd61045946bfd8c01f8168fb286dfe6101473
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.2.3 (2014-05-04)
2
+
3
+ * Changed Messenger `debug` method to be conditional
4
+ * Fixed a few bugs in Pref Actions
5
+ * Fixed Pref spec
6
+
1
7
  # 2.2.2 (2014-05-04)
2
8
 
3
9
  * Added dot-notation syntax for Hash extensions
@@ -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.2'
11
+ VERSION = '2.2.3'
12
12
  end
@@ -23,7 +23,7 @@ module CLIUtils
23
23
  # only send it to the Logger targets.
24
24
  # @return [void]
25
25
  def debug(m)
26
- @targets.each { |_, t| t.debug(m) }
26
+ @targets.each { |_, t| t.debug { m } }
27
27
  end
28
28
 
29
29
  # Detaches a delegation target.
@@ -187,39 +187,35 @@ module CLIUtils
187
187
  ret
188
188
  end
189
189
 
190
- # Evaluates the pre-prompt Hash and does the right thing. :)
191
- # @return [void]
192
- def _eval_pre
193
- messenger.info(@pre[:message])
190
+ def _eval_action(type = 'pre')
191
+ messenger.info(instance_variable_get("@#{ type }")[:message])
194
192
  messenger.prompt('Press enter to continue')
195
193
 
196
- if (@pre[:action])
197
- action_obj = _init_action(@pre[:action])
194
+ if instance_variable_get("@#{ type }")[:action]
195
+ action_obj = _init_action(instance_variable_get("@#{ type }")[:action])
198
196
  action_obj.run if action_obj
199
197
  end
200
198
  end
201
199
 
200
+ # Evaluates the pre-prompt Hash and does the right thing. :)
201
+ # @return [void]
202
+ def _eval_pre
203
+ _eval_action('pre')
204
+ end
205
+
202
206
  # Evaluates the post-prompt Hash and does the right thing. :)
203
207
  # @return [void]
204
208
  def _eval_post
205
- messenger.info(@post[:message])
206
- messenger.prompt('Press enter to continue')
207
-
208
- if (@post[:action])
209
- action_obj = _init_action(@post[:action])
210
- action_obj.run if action_obj
211
- end
209
+ _eval_action('post')
212
210
  end
213
211
 
214
212
  # Attempts to instantiate a Pre or Post Action based on name; if
215
213
  # successful, the new object gets placed in @validator_objects
216
- # @param [String] path_or_name The path to or name of the Action
214
+ # @param [Hash] action_hash The hash of action data (name, params, etc.)
217
215
  # @return [void]
218
- def _init_action(path_or_name)
219
- obj = _load_asset(ASSET_TYPE_ACTION, path_or_name)
220
- unless obj.nil? || @pre[:parameters].nil?
221
- obj.parameters = @pre[:parameters]
222
- end
216
+ def _init_action(action_hash)
217
+ obj = _load_asset(ASSET_TYPE_ACTION, action_hash[:name])
218
+ obj.parameters = action_hash[:parameters]
223
219
  obj
224
220
  end
225
221
 
@@ -254,6 +250,7 @@ module CLIUtils
254
250
  # @return [Object]
255
251
  def _load_asset(type, path_or_name)
256
252
  asset_found = false
253
+
257
254
  if File.file?(File.expand_path(path_or_name))
258
255
  # If the file exists, we're assuming that the user
259
256
  # passed a filepath.
data/spec/pref_spec.rb CHANGED
@@ -20,14 +20,18 @@ describe CLIUtils::Pref do
20
20
  options: ['bachya'],
21
21
  pre: {
22
22
  message: 'Test pre message',
23
- action: "#{ File.join(base_path, 'test_action.rb') }",
24
- parameters: {
25
- param1: 'value1'
23
+ action: {
24
+ name: "#{ File.join(base_path, 'test_action.rb') }",
25
+ parameters: {
26
+ param1: 'value1'
27
+ }
26
28
  }
27
29
  },
28
30
  post: {
29
31
  message: 'Test post message',
30
- action: "#{ File.join(base_path, 'test_action.rb') }"
32
+ action: {
33
+ name: "#{ File.join(base_path, 'test_action.rb') }"
34
+ }
31
35
  },
32
36
  prereqs: [
33
37
  { config_section: 'section' },
@@ -47,14 +51,18 @@ describe CLIUtils::Pref do
47
51
  options: ['bachya'],
48
52
  pre: {
49
53
  message: 'Test pre message',
50
- action: 'test',
51
- parameters: {
52
- param1: 'value1'
54
+ action: {
55
+ name: 'test',
56
+ parameters: {
57
+ param1: 'value1'
58
+ }
53
59
  }
54
60
  },
55
61
  post: {
56
62
  message: 'Test post message',
57
- action: 'test'
63
+ action: {
64
+ name: 'test'
65
+ }
58
66
  },
59
67
  prereqs: [
60
68
  { config_section: 'section' },
@@ -94,8 +102,8 @@ describe CLIUtils::Pref do
94
102
  expect(pref.default).to eq(pref_data[:default])
95
103
  expect(pref.last_error_message).to eq(nil)
96
104
  expect(pref.options).to eq(['bachya'])
97
- expect(pref.post).to eq({ message: 'Test post message', action: "#{ File.join(base_path, 'test_action.rb') }" })
98
- expect(pref.pre).to eq({message: 'Test pre message', action: "#{ File.join(base_path, 'test_action.rb') }", parameters: { param1: 'value1' } })
105
+ expect(pref.post).to eq({message: 'Test post message', action: { name: '/Users/abach/Git/cliutils/spec/../support/test_action.rb' } })
106
+ expect(pref.pre).to eq({message: 'Test pre message', action: { name: '/Users/abach/Git/cliutils/spec/../support/test_action.rb', parameters: { param1: 'value1'} } })
99
107
  expect(pref.prereqs).to eq([{ config_section: 'section' }, { config_value: 'value' }])
100
108
  expect(pref.validator_objects[0].class).to eq(CLIUtils::TestValidator)
101
109
  expect(pref.validators).to eq([File.join(base_path, 'test_validator.rb')])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach