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 +10 -0
- data/lib/kronk.rb +3 -3
- data/lib/kronk/cmd.rb +18 -6
- data/lib/kronk/path/match.rb +7 -3
- data/lib/kronk/path/matcher.rb +1 -1
- data/lib/kronk/path/transaction.rb +9 -4
- data/lib/kronk/player.rb +2 -4
- data/test/test_cmd.rb +1 -1
- data/test/test_helper.rb +2 -2
- data/test/test_path.rb +5 -4
- data/test/test_path_matcher.rb +12 -11
- data/test/test_transaction.rb +2 -0
- metadata +2 -2
data/History.rdoc
CHANGED
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.
|
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
|
541
|
-
error e
|
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
|
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
|
-
|
653
|
-
|
654
|
-
|
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
|
|
data/lib/kronk/path/match.rb
CHANGED
@@ -12,10 +12,14 @@ class Kronk::Path::Match < Array
|
|
12
12
|
end
|
13
13
|
|
14
14
|
|
15
|
-
def []
|
15
|
+
def [] selector
|
16
16
|
path_match = super
|
17
|
-
|
18
|
-
|
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
|
|
data/lib/kronk/path/matcher.rb
CHANGED
@@ -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
|
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
|
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) &&
|
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)
|
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
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 "\
|
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 [/\
|
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', /\
|
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', /\
|
252
|
+
assert_path ['path', ['to', /\A(?:foo|bar)\Z/], 'item'],
|
253
253
|
"path/to=foo|bar/item"
|
254
254
|
|
255
|
-
assert_path
|
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
|
|
data/test/test_path_matcher.rb
CHANGED
@@ -28,8 +28,8 @@ class TestPathMatcher < Test::Unit::TestCase
|
|
28
28
|
|
29
29
|
|
30
30
|
def test_new
|
31
|
-
assert_equal %r{\
|
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(/\
|
343
|
-
assert_equal(/\A(.?)test(.*)\Z/, @matcher.parse_node("?test*"))
|
344
|
-
assert_equal(/\A
|
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
|
-
|
349
|
-
assert_equal(/\
|
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(/\
|
353
|
+
assert_equal(/\A(?:a|b(c|d))\Z/i, matcher.parse_node("a|b(c|d)"))
|
353
354
|
end
|
354
355
|
|
355
356
|
|
data/test/test_transaction.rb
CHANGED
@@ -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.
|
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-
|
13
|
+
date: 2011-10-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|