kronk 1.7.3 → 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,13 @@
1
+ === 1.7.3 / 2011-10-26
2
+
3
+ * Bugfixes:
4
+
5
+ * Support converting root transaction hash to array.
6
+
7
+ * Fix for single item selection in Path::Match.
8
+
9
+ * Fix for overly-eager Path::Matcher regexp.
10
+
1
11
  === 1.7.3 / 2011-10-25
2
12
 
3
13
  * Bugfixes:
data/lib/kronk.rb CHANGED
@@ -14,7 +14,7 @@ require 'yaml'
14
14
  class Kronk
15
15
 
16
16
  # This gem's version.
17
- VERSION = '1.7.3'
17
+ VERSION = '1.7.4'
18
18
 
19
19
  require 'kronk/constants'
20
20
  require 'kronk/queue_runner'
@@ -354,8 +354,8 @@ class Kronk
354
354
 
355
355
  resp
356
356
 
357
- rescue SocketError, SystemCallError
358
- raise NotFoundError, "#{uri} could not be found"
357
+ rescue SocketError, SystemCallError => e
358
+ raise NotFoundError, "#{uri} could not be found (#{e.class})"
359
359
 
360
360
  rescue Timeout::Error
361
361
  raise TimeoutError, "#{uri} took too long to respond"
data/lib/kronk/cmd.rb CHANGED
@@ -5,6 +5,11 @@ class Kronk
5
5
 
6
6
  class Cmd
7
7
 
8
+ RESCUABLE = [
9
+ Kronk::Exception, Timeout::Error,
10
+ SocketError, SystemCallError, URI::InvalidURIError
11
+ ]
12
+
8
13
  ##
9
14
  # Saves the raw http response to a cache file.
10
15
 
@@ -537,8 +542,8 @@ Parse and run diffs against data from live and cached http responses.
537
542
 
538
543
  exit 1 unless success
539
544
 
540
- rescue Kronk::Exception, SystemCallError => e
541
- error e.message, e.backtrace
545
+ rescue *RESCUABLE => e
546
+ error e
542
547
  exit 2
543
548
  end
544
549
 
@@ -647,11 +652,18 @@ Parse and run diffs against data from live and cached http responses.
647
652
 
648
653
 
649
654
  ##
650
- # Print an error string
655
+ # Print an error from a String or Exception instance
656
+
657
+ def self.error err, more=nil
658
+ msg = ::Exception === err ?
659
+ "#{err.class}: #{err.message}" : "Error: #{err}"
651
660
 
652
- def self.error str, more=nil
653
- $stderr.puts "\nError: #{str}"
654
- $stderr.puts more if Kronk.config[:verbose] && more
661
+ $stderr.puts "\n#{msg}"
662
+
663
+ if Kronk.config[:verbose]
664
+ more ||= err.backtrace.join("\n") if ::Exception === err
665
+ $stderr.puts "#{more}" if more
666
+ end
655
667
  end
656
668
 
657
669
 
@@ -12,10 +12,14 @@ class Kronk::Path::Match < Array
12
12
  end
13
13
 
14
14
 
15
- def [] *args
15
+ def [] selector
16
16
  path_match = super
17
- path_match.matches = @matches.dup
18
- path_match.splat = @splat.map{|key, sp| [key, sp.dup]}
17
+
18
+ if self.class === path_match
19
+ path_match.matches = @matches.dup
20
+ path_match.splat = @splat.map{|key, sp| [key, sp.dup]}
21
+ end
22
+
19
23
  path_match
20
24
  end
21
25
 
@@ -180,7 +180,7 @@ class Kronk::Path::Matcher
180
180
  str.gsub! %r{(^|[^#{Kronk::Path::RECH}])([#{SUFF_CHARS}])}, '\1(.\2)'
181
181
  str.gsub! %r{(^|[^\.#{Kronk::Path::RECH}])([#{SUFF_CHARS}])}, '\1(.\2)'
182
182
 
183
- Regexp.new "\\A#{str}\\Z", @regex_opts
183
+ Regexp.new "\\A(?:#{str})\\Z", @regex_opts
184
184
 
185
185
  else
186
186
  str.gsub %r{#{Kronk::Path::RECH}([^#{Kronk::Path::RECH}]|$)}, '\1'
@@ -101,7 +101,7 @@ class Kronk::Path::Transaction
101
101
  end
102
102
 
103
103
  new_data = hash_to_ary new_data if
104
- Array === @data && Hash === new_data &&
104
+ (remake_paths.last == [] || Array === @data && Hash === new_data) &&
105
105
  (!except_modified || @data.length == new_data.length)
106
106
 
107
107
  new_data
@@ -159,7 +159,7 @@ class Kronk::Path::Transaction
159
159
  remap_make_arrays(tpath, path)
160
160
  end
161
161
 
162
- force_assign_paths data.class.new, path_val_hash
162
+ force_assign_paths [], path_val_hash
163
163
  end
164
164
 
165
165
 
@@ -242,7 +242,7 @@ class Kronk::Path::Transaction
242
242
 
243
243
  new_curr_data[key] = value and break if last
244
244
 
245
- if ary_or_hash?(curr_data) && ary_or_hash?(curr_data[key])
245
+ if ary_or_hash?(curr_data) && child_ary_or_hash?(curr_data, key)
246
246
  new_curr_data[key] ||= curr_data[key]
247
247
 
248
248
  elsif !ary_or_hash?(new_curr_data[key])
@@ -254,7 +254,7 @@ class Kronk::Path::Transaction
254
254
  prev_key = key
255
255
  prev_data = new_curr_data
256
256
  new_curr_data = new_curr_data[key]
257
- curr_data = ary_or_hash?(curr_data) ? curr_data[key] : nil
257
+ curr_data = curr_data[key] if ary_or_hash?(curr_data) rescue nil
258
258
  end
259
259
  end
260
260
 
@@ -272,6 +272,11 @@ class Kronk::Path::Transaction
272
272
  end
273
273
 
274
274
 
275
+ def child_ary_or_hash? obj, key
276
+ ary_or_hash?(obj[key]) rescue false
277
+ end
278
+
279
+
275
280
  def ary_to_hash ary # :nodoc:
276
281
  hash = {}
277
282
  ary.each_with_index{|val, i| hash[i] = val}
data/lib/kronk/player.rb CHANGED
@@ -8,8 +8,6 @@ class Kronk
8
8
 
9
9
  class Player < QueueRunner
10
10
 
11
- RESCUABLE = [Kronk::Exception, SystemCallError, URI::InvalidURIError]
12
-
13
11
  attr_accessor :input, :output
14
12
 
15
13
  ##
@@ -126,7 +124,7 @@ class Kronk
126
124
 
127
125
  begin
128
126
  kronk.send(*args)
129
- rescue *RESCUABLE => e
127
+ rescue *Kronk::Cmd::RESCUABLE => e
130
128
  err = e
131
129
  end
132
130
 
@@ -149,7 +147,7 @@ class Kronk
149
147
  method = args.shift.to_s + '_async'
150
148
 
151
149
  kronk.send(method, *args) do |obj, err|
152
- raise err if err && !RESCUABLE.find{|eclass| eclass === err}
150
+ raise err if err && !Kronk::Cmd::RESCUABLE.find{|eclass| eclass === err}
153
151
  trigger_result kronk, err, &block
154
152
  end
155
153
  end
data/test/test_cmd.rb CHANGED
@@ -497,7 +497,7 @@ class TestCmd < Test::Unit::TestCase
497
497
 
498
498
  errs.each do |err, msg|
499
499
  Kronk.expects(:load_config)
500
- expect_error_output msg
500
+ expect_error_output msg, err
501
501
  Kronk::Cmd.expects(:request).raises(err)
502
502
 
503
503
  assert_exit 2 do
data/test/test_helper.rb CHANGED
@@ -113,8 +113,8 @@ def expect_request_output str, opts={}
113
113
  end
114
114
 
115
115
 
116
- def expect_error_output str
117
- $stderr.expects(:puts).with "\nError: #{str}"
116
+ def expect_error_output str, name="Error"
117
+ $stderr.expects(:puts).with "\n#{name}: #{str}"
118
118
  end
119
119
 
120
120
 
data/test/test_path.rb CHANGED
@@ -237,10 +237,10 @@ class TestPath < Test::Unit::TestCase
237
237
 
238
238
  assert_path %w{path/to item/ i}, "path\\/to/item\\//i"
239
239
 
240
- assert_path [/\Apath\/\.to\Z/i, /\Aitem\Z/i],
240
+ assert_path [/\A(?:path\/\.to)\Z/i, /\A(?:item)\Z/i],
241
241
  "path\\/.to/item", Regexp::IGNORECASE
242
242
 
243
- assert_path ['path', /\Ato|for\Z/, 'item'], "path/to|for/item"
243
+ assert_path ['path', /\A(?:to|for)\Z/, 'item'], "path/to|for/item"
244
244
  end
245
245
 
246
246
 
@@ -249,10 +249,11 @@ class TestPath < Test::Unit::TestCase
249
249
  assert_path ['path', ["*", 'foo'], 'item'], "path/*=foo/item"
250
250
  assert_path ['path', [nil, 'foo'], 'item'], "path/=foo/item"
251
251
 
252
- assert_path ['path', ['to', /\Afoo|bar\Z/], 'item'],
252
+ assert_path ['path', ['to', /\A(?:foo|bar)\Z/], 'item'],
253
253
  "path/to=foo|bar/item"
254
254
 
255
- assert_path [/\Apath\Z/i, [/\Ato\Z/i, /\Afoo\Z/i], /\Aitem\Z/i],
255
+ assert_path \
256
+ [/\A(?:path)\Z/i, [/\A(?:to)\Z/i, /\A(?:foo)\Z/i], /\A(?:item)\Z/i],
256
257
  "path/to=foo/item", Regexp::IGNORECASE
257
258
  end
258
259
 
@@ -28,8 +28,8 @@ class TestPathMatcher < Test::Unit::TestCase
28
28
 
29
29
 
30
30
  def test_new
31
- assert_equal %r{\Afoo(.*)\Z}, @matcher.key
32
- assert_equal %r{\A(.*)bar(.*)\Z}, @matcher.value
31
+ assert_equal %r{\A(?:foo(.*))\Z}, @matcher.key
32
+ assert_equal %r{\A(?:(.*)bar(.*))\Z}, @matcher.value
33
33
  assert !@matcher.recursive
34
34
  end
35
35
 
@@ -339,17 +339,18 @@ class TestPathMatcher < Test::Unit::TestCase
339
339
 
340
340
 
341
341
  def test_parse_node_regex
342
- assert_equal(/\Atest(.*)\Z/, @matcher.parse_node("test*"))
343
- assert_equal(/\A(.?)test(.*)\Z/, @matcher.parse_node("?test*"))
344
- assert_equal(/\A\?test(.*)\Z/, @matcher.parse_node("\\?test*"))
345
- assert_equal(/\A(.?)test\*(.*)\Z/, @matcher.parse_node("?test\\**"))
346
- assert_equal(/\A(.?)test(.*)\Z/, @matcher.parse_node("?test*?**??"))
347
- assert_equal(/\A(.?)test(.?)(.?)(.*)\Z/, @matcher.parse_node("?test??**??"))
348
- assert_equal(/\Aa|b\Z/, @matcher.parse_node("a|b"))
349
- assert_equal(/\Aa|b(c|d)\Z/, @matcher.parse_node("a|b(c|d)"))
342
+ assert_equal(/\A(?:test(.*))\Z/, @matcher.parse_node("test*"))
343
+ assert_equal(/\A(?:(.?)test(.*))\Z/, @matcher.parse_node("?test*"))
344
+ assert_equal(/\A(?:\?test(.*))\Z/, @matcher.parse_node("\\?test*"))
345
+ assert_equal(/\A(?:(.?)test\*(.*))\Z/, @matcher.parse_node("?test\\**"))
346
+ assert_equal(/\A(?:(.?)test(.*))\Z/, @matcher.parse_node("?test*?**??"))
347
+ assert_equal(/\A(?:(.?)test(.?)(.?)(.*))\Z/,
348
+ @matcher.parse_node("?test??**??"))
349
+ assert_equal(/\A(?:a|b)\Z/, @matcher.parse_node("a|b"))
350
+ assert_equal(/\A(?:a|b(c|d))\Z/, @matcher.parse_node("a|b(c|d)"))
350
351
 
351
352
  matcher = Kronk::Path::Matcher.new :regex_opts => Regexp::IGNORECASE
352
- assert_equal(/\Aa|b(c|d)\Z/i, matcher.parse_node("a|b(c|d)"))
353
+ assert_equal(/\A(?:a|b(c|d))\Z/i, matcher.parse_node("a|b(c|d)"))
353
354
  end
354
355
 
355
356
 
@@ -459,6 +459,8 @@ class TestTransaction < Test::Unit::TestCase
459
459
  assert_equal expected, new_data
460
460
 
461
461
  expected[3]['other'] = ['val4', 'val3', ['val5']]
462
+ expected = @trans.hash_to_ary expected
463
+
462
464
  new_data = @trans.remake_arrays new_data
463
465
  assert_equal expected, new_data
464
466
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kronk
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.7.3
5
+ version: 1.7.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremie Castagna
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-25 00:00:00 Z
13
+ date: 2011-10-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json