kronk 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,31 @@
1
+ === 1.4.0 / 2011-07-04
2
+
3
+ * Enhancements:
4
+
5
+ * Rewrote data path parsing to be more efficient and powerful. Added support
6
+ for ../ and ./ paradygms replacing the ':path' notation.
7
+
8
+ * Added path modifiers for case-insensitive and multiline matcher support.
9
+ Paths are once again case-sensitive by default.
10
+
11
+ * Created non-destructive path transactions to replace the DataSet
12
+ in-place modification.
13
+
14
+ * Support for displaying data indicies of modified Arrays.
15
+
16
+ * Removed explicit dependencies for ActiveSupport. Will attempt loading only
17
+ if String#pluralize isn't defined. Otherwise uses naïve pluralization.
18
+
19
+ * Removed Rack dependency.
20
+
21
+ * Made Kronk.compare concurrent for better performance.
22
+
23
+ * Bugfixes:
24
+
25
+ * Mixed-type sorting of Hash keys when creating ordered data String.
26
+
27
+ * Data selections no longer have nil values on non-selected array elements.
28
+
1
29
  === 1.3.1 / 2011-06-01
2
30
 
3
31
  * Bugfixes:
@@ -11,6 +11,8 @@ lib/kronk/data_set.rb
11
11
  lib/kronk/diff.rb
12
12
  lib/kronk/diff/ascii_format.rb
13
13
  lib/kronk/diff/color_format.rb
14
+ lib/kronk/path.rb
15
+ lib/kronk/path/transaction.rb
14
16
  lib/kronk/plist_parser.rb
15
17
  lib/kronk/request.rb
16
18
  lib/kronk/response.rb
@@ -36,6 +38,8 @@ test/test_data_set.rb
36
38
  test/test_diff.rb
37
39
  test/test_helper.rb
38
40
  test/test_kronk.rb
41
+ test/test_path.rb
39
42
  test/test_request.rb
40
43
  test/test_response.rb
44
+ test/test_transaction.rb
41
45
  test/test_xml_parser.rb
@@ -75,7 +75,7 @@ Parse the data and run an IRB console with the response:
75
75
 
76
76
  == CONFIGURATION:
77
77
 
78
- Kronk pulls it's config from $HOME/.kronk and supports the following:
78
+ Kronk pulls it's config from $HOME/.kronk/rc and supports the following:
79
79
 
80
80
  Set the file to save the last http response retrieved in:
81
81
 
@@ -162,12 +162,9 @@ something like:
162
162
  "data" => {
163
163
  "path1" => "value1",
164
164
  "path2" => [
165
- nil,
166
165
  {
167
166
  "child" => "child value"
168
- },
169
- nil,
170
- nil
167
+ }
171
168
  ]
172
169
  }
173
170
  }
@@ -186,10 +183,9 @@ flag it to remove data:
186
183
  }
187
184
 
188
185
  If you would like to exclude or include only items with a specific child
189
- attribute, you can do so by prepending the path with a ':'.
190
- Both ':' and '-' can be combined as ':-'.
186
+ attribute, you can do so by appending "/.." to the path.
191
187
 
192
- $ kronk http://host.com -- :data/path2/1/child
188
+ $ kronk http://host.com -- data/path2/1/child/..
193
189
 
194
190
  {
195
191
  "data" => {
@@ -200,12 +196,42 @@ Both ':' and '-' can be combined as ':-'.
200
196
  "child" => "child value",
201
197
  "last_child" => "last value"
202
198
  },
203
- nil,
204
- nil
205
199
  ]
206
200
  }
207
201
  }
208
202
 
203
+ Path matcher parsing may also be affected by appending Regexp options to the
204
+ end of the path in the following fashion:
205
+
206
+ # Make path case insensitive
207
+ $ kronk host.com -- data/path2/1//i
208
+
209
+ {
210
+ "data" => {
211
+ "PATH2" => [
212
+ "item at index 1"
213
+ ],
214
+
215
+ "path2" => [
216
+ {
217
+ "first_child" => "first value",
218
+ "child" => "child value",
219
+ "last_child" => "last value"
220
+ }
221
+ ]
222
+ }
223
+ }
224
+
225
+ # Make path case insensitive and multiline
226
+ $ kronk host.com -- data/**=*foobar*//im
227
+
228
+ {
229
+ "data" => {
230
+ "subdata" => "test for\nFOOBAR\nmultiline"
231
+ }
232
+ }
233
+
234
+
209
235
  There are additionally a variety of wildcard and special characters that
210
236
  are supported:
211
237
 
@@ -213,24 +239,28 @@ are supported:
213
239
 
214
240
  * \*\*/ matches any key recursively down the data structure
215
241
 
242
+ * ../ matches the parent of the previously matched item
243
+
244
+ * 2..5, 2...6 and 2,3 match any Integer or String from 2 to 5
245
+
216
246
  * ? matches zero or one character
217
247
 
218
248
  * | effectively works as an "OR" character, matches /^val1|val2$/
219
249
 
220
- * \= is used to match values and may be used in conjuction with a key or not.
250
+ * \= is used to match values and may be used in conjuction with a key or not
221
251
 
222
- * Parentheses are ok to use if in conjunction with other special characters
252
+ * Parentheses may be used in conjunction with other special characters
223
253
  for a given path item, such as: /path(1|2)
224
254
 
225
- Check out Kronk::DataSet for more details on data traversing.
255
+ * \\ escapes any special path character
256
+
257
+ Check out Kronk::Path and Kronk::DataSet for more details on data traversing.
226
258
 
227
259
  Note: Bash may try to parse your data paths, especially if they start with
228
260
  wildcards or if they contain the pipe "|" character, so you may need to put
229
261
  single quotes around some of your paths.
230
-
231
- == REQUIREMENTS:
232
262
 
233
- * activesupport gem
263
+ == REQUIREMENTS:
234
264
 
235
265
  * nokogiri gem
236
266
 
@@ -238,8 +268,6 @@ single quotes around some of your paths.
238
268
 
239
269
  * json gem
240
270
 
241
- * rack gem
242
-
243
271
  * cookiejar gem
244
272
 
245
273
  == INSTALL:
data/Rakefile CHANGED
@@ -25,10 +25,7 @@ Hoe.spec 'kronk' do
25
25
  self.extra_deps << ['plist', '~>3.1.0']
26
26
  self.extra_deps << ['json', '~>1.5']
27
27
  self.extra_deps << ['nokogiri', '~>1.4']
28
- self.extra_deps << ['i18n', '>=0.5']
29
- self.extra_deps << ['activesupport', '>=2.0.0']
30
28
  self.extra_deps << ['cookiejar', '~>0.3.0']
31
- self.extra_deps << ['rack', '~>1.0']
32
29
 
33
30
  self.extra_dev_deps << ['mocha', '~>0.9.10']
34
31
  end
data/bin/kronk CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << File.join(File.dirname(__FILE__), "../lib")
3
+ $: << File.join(File.dirname(__FILE__), "../lib") if $0 =~ %r{bin/kronk$}
4
+
4
5
  begin
5
6
  require 'kronk'
6
7
 
@@ -2,7 +2,6 @@ require 'rubygems'
2
2
 
3
3
  require 'json'
4
4
  require 'cookiejar'
5
- require 'rack'
6
5
 
7
6
  require 'net/https'
8
7
  require 'optparse'
@@ -11,10 +10,12 @@ require 'yaml'
11
10
  class Kronk
12
11
 
13
12
  # This gem's version.
14
- VERSION = '1.3.1'
13
+ VERSION = '1.4.0'
15
14
 
16
15
 
17
16
  require 'kronk/cmd'
17
+ require 'kronk/path'
18
+ require 'kronk/path/transaction'
18
19
  require 'kronk/data_set'
19
20
  require 'kronk/diff/ascii_format'
20
21
  require 'kronk/diff/color_format'
@@ -169,9 +170,9 @@ class Kronk
169
170
 
170
171
  # Hash or uri query String
171
172
  when :data, :query
172
- val = Rack::Utils.parse_nested_query val if String === val
173
+ val = Request.parse_nested_query val if String === val
173
174
 
174
- out_opts[key] = Rack::Utils.parse_nested_query out_opts[key] if
175
+ out_opts[key] = Request.parse_nested_query out_opts[key] if
175
176
  String === out_opts[key]
176
177
 
177
178
  out_opts[key] = val.merge out_opts[key], &DataSet::DEEP_MERGE
@@ -312,25 +313,30 @@ class Kronk
312
313
  # Supports the following options:
313
314
  # :data:: Hash/String - the data to pass to the http request
314
315
  # :query:: Hash/String - the data to append to the http request path
315
- # :follow_redirects:: Integer/Bool - number of times to follow redirects
316
+ # :follow_redirects:: Integer/Boolean - number of times to follow redirects
316
317
  # :headers:: Hash - extra headers to pass to the request
317
318
  # :http_method:: Symbol - the http method to use; defaults to :get
318
319
  # :user_agent:: String - user agent string or alias; defaults to 'kronk'
319
320
  # :auth:: Hash - must contain :username and :password; defaults to nil
320
321
  # :proxy:: Hash/String - http proxy to use; defaults to nil
321
322
  # :only_data:: String/Array - extracts the data from given data paths
322
- # :only_data_with:: String/Array - extracts the data from given parent paths
323
323
  # :ignore_data:: String/Array - defines which data points to exclude
324
- # :ignore_data_with:: String/Array - defines which parent data to exclude
325
- # :with_headers:: Bool/String/Array - defines which headers to include
326
- # :parser:: Object/String - The parser to use for the body; default nil
327
- # :raw:: Bool - run diff on raw strings
324
+ # :keep_indicies:: Boolean - keep the original indicies of modified arrays,
325
+ # and return them as hashes.
326
+ # :with_headers:: Boolean/String/Array - defines which headers to include
327
+ # :parser:: Object/String - the parser to use for the body; default nil
328
+ # :raw:: Boolean - run diff on raw strings
328
329
  #
329
330
  # Returns a diff object.
330
331
 
331
332
  def self.compare uri1, uri2, options={}
332
- str1 = retrieve_data_string uri1, options
333
- str2 = retrieve_data_string uri2, options
333
+ str1 = str2 = ""
334
+
335
+ t1 = Thread.new{ str1 = retrieve_data_string uri1, options }
336
+ t2 = Thread.new{ str2 = retrieve_data_string uri2, options }
337
+
338
+ t1.join
339
+ t2.join
334
340
 
335
341
  Diff.new str1, str2
336
342
  end
@@ -346,7 +352,7 @@ class Kronk
346
352
  resp = Request.retrieve uri, options
347
353
 
348
354
  if options[:irb]
349
- irb resp
355
+ Cmd.irb resp
350
356
 
351
357
  elsif options[:raw]
352
358
  resp.selective_string options
@@ -362,89 +368,4 @@ class Kronk
362
368
  end
363
369
  end
364
370
  end
365
-
366
-
367
- ###
368
- # Deprecated methods...
369
- ###
370
-
371
-
372
- def self.deprecated method_name, replacement=nil
373
- replacement &&= ", use #{replacement}"
374
- replacement ||= " with no replacement"
375
-
376
- Cmd.warn "#{method_name} deprecated#{replacement}"
377
- end
378
-
379
-
380
- ##
381
- # Deprecated! Use Kronk::Cmd::irb
382
-
383
- def self.irb resp
384
- deprecated "Kronk::irb", "Kronk::Cmd::irb"
385
- Cmd.irb resp
386
- end
387
-
388
-
389
- ##
390
- # Deprecated! Use Kronk::Cmd::move_config_file
391
-
392
- def self.move_config_file
393
- deprecated "Kronk::move_config_file", "Kronk::Cmd::move_config_file"
394
- Cmd.move_config_file
395
- end
396
-
397
-
398
- ##
399
- # Deprecated! Use Kronk::Cmd::query_password
400
-
401
- def self.query_password str=nil
402
- deprecated "Kronk::query_password", "Kronk::Cmd::query_password"
403
- Cmd.query_password str
404
- end
405
-
406
-
407
- ##
408
- # Deprecated! Use Kronk::Cmd::parse_args
409
-
410
- def self.parse_args argv
411
- deprecated "Kronk::parse_args", "Kronk::Cmd::parse_args"
412
- Cmd.parse_args argv
413
- end
414
-
415
-
416
- ##
417
- # Deprecated! Use Kronk::Cmd::parse_data_path_args
418
-
419
- def self.parse_data_path_args options, argv
420
- deprecated "Kronk::parse_data_path_args", "Kronk::Cmd::parse_data_path_args"
421
- Cmd.parse_data_path_args options, argv
422
- end
423
-
424
-
425
- ##
426
- # Deprecated! Use Kronk::Cmd::run
427
-
428
- def self.run argv=ARGV
429
- deprecated "Kronk::run", "Kronk::Cmd::run"
430
- Cmd.run argv
431
- end
432
-
433
-
434
- ##
435
- # Deprecated! Use Kronk::Cmd::verbose
436
-
437
- def self.verbose str
438
- deprecated "Kronk::verbose", "Kronk::Cmd::verbose"
439
- Cmd.verbose str
440
- end
441
-
442
-
443
- ##
444
- # Deprecated! Use Kronk::Cmd::windows?
445
-
446
- def self.windows?
447
- deprecated "Kronk::windows?", "Kronk::Cmd::windows?"
448
- Cmd.windows?
449
- end
450
371
  end
@@ -67,11 +67,11 @@ class Kronk
67
67
 
68
68
  def self.parse_args argv
69
69
  options = {
70
- :auth => {},
71
- :no_body => false,
72
- :proxy => {},
73
- :uris => [],
74
- :with_headers => false
70
+ :auth => {},
71
+ :no_body => false,
72
+ :proxy => {},
73
+ :uris => [],
74
+ :with_headers => false
75
75
  }
76
76
 
77
77
  options = parse_data_path_args options, argv
@@ -90,7 +90,7 @@ Parse and run diffs against data from live and cached http responses.
90
90
  Usage:
91
91
  #{opt.program_name} --help
92
92
  #{opt.program_name} --version
93
- #{opt.program_name} uri1 [uri2] [options...] [-- data-paths]
93
+ #{opt.program_name} uri1 [uri2] [options] [-- data-paths]
94
94
 
95
95
  Examples:
96
96
  #{opt.program_name} http://example.com/A
@@ -100,8 +100,6 @@ Parse and run diffs against data from live and cached http responses.
100
100
 
101
101
  Arguments after -- will be used to focus the diff on specific data points.
102
102
  If the data paths start with a '-' the matched data points will be removed.
103
- If the data paths start with a ":" the parent of the matched data is used.
104
- The ':' and '-' modifiers may be used together in that order (':-').
105
103
 
106
104
  Options:
107
105
  STR
@@ -168,6 +166,11 @@ Parse and run diffs against data from live and cached http responses.
168
166
  end
169
167
 
170
168
 
169
+ opt.on('--indicies', 'Show modified array original indicies') do
170
+ options[:keep_indicies] = true
171
+ end
172
+
173
+
171
174
  opt.on('--irb', 'Start an IRB console') do
172
175
  options[:irb] = true
173
176
  end
@@ -190,7 +193,7 @@ Parse and run diffs against data from live and cached http responses.
190
193
 
191
194
 
192
195
  opt.on('--prev', 'Use last response to diff against') do
193
- options[:uris].unshift :cache
196
+ options[:uris].unshift Kronk.config[:cache_file]
194
197
  end
195
198
 
196
199
 
@@ -319,6 +322,11 @@ Parse and run diffs against data from live and cached http responses.
319
322
  options[:uris].concat argv
320
323
  options[:uris].slice!(2..-1)
321
324
 
325
+ if options[:uris].empty? && File.file?(Kronk.config[:cache_file])
326
+ verbose "No URI specified - using kronk cache"
327
+ options[:uris] << Kronk.config[:cache_file]
328
+ end
329
+
322
330
  argv.clear
323
331
 
324
332
  raise OptionParser::MissingArgument, "You must enter at least one URI" if
@@ -348,9 +356,11 @@ Parse and run diffs against data from live and cached http responses.
348
356
  (options[:ignore_data] ||= []) << path[1..-1]
349
357
 
350
358
  elsif path[0,2] == ":-"
359
+ warn "The :path notation is deprecated, use path/.."
351
360
  (options[:ignore_data_with] ||= []) << path[2..-1]
352
361
 
353
362
  elsif path[0,1] == ":"
363
+ warn "The :path notation is deprecated, use path/.."
354
364
  (options[:only_data_with] ||= []) << path[1..-1]
355
365
 
356
366
  else
@@ -380,9 +390,6 @@ Parse and run diffs against data from live and cached http responses.
380
390
  # Runs the kronk command with the given terminal args.
381
391
 
382
392
  def self.run argv=ARGV
383
-
384
- options = parse_args argv
385
-
386
393
  begin
387
394
  Kronk.load_config
388
395
 
@@ -402,6 +409,8 @@ Parse and run diffs against data from live and cached http responses.
402
409
  exit 2
403
410
  end
404
411
 
412
+ options = parse_args argv
413
+
405
414
  Kronk.load_cookie_jar
406
415
 
407
416
  load_requires options[:requires]
@@ -423,6 +432,7 @@ Parse and run diffs against data from live and cached http responses.
423
432
 
424
433
  if uri1 && uri2
425
434
  diff = Kronk.compare uri1, uri2, options
435
+
426
436
  puts "#{diff.formatted}\n" unless Kronk.config[:brief]
427
437
 
428
438
  if Kronk.config[:verbose] || Kronk.config[:brief]