sauce_whisk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +37 -0
  6. data/Rakefile +10 -0
  7. data/lib/sauce_whisk/assets.rb +25 -0
  8. data/lib/sauce_whisk/jobs.rb +112 -0
  9. data/lib/sauce_whisk/rest_request_builder.rb +29 -0
  10. data/lib/sauce_whisk/version.rb +3 -0
  11. data/lib/sauce_whisk.rb +23 -0
  12. data/sauce_whisk.gemspec +27 -0
  13. data/spec/fixtures/vcr_cassettes/assets.yml +161478 -0
  14. data/spec/fixtures/vcr_cassettes/jobs.yml +256 -0
  15. data/spec/fixtures/vcr_cassettes/no_jobs.yml +0 -0
  16. data/spec/fixtures/vcr_cassettes/rest_request.yml +0 -0
  17. data/spec/lib/sauce_whisk/asset_spec.rb +39 -0
  18. data/spec/lib/sauce_whisk/assets_spec.rb +27 -0
  19. data/spec/lib/sauce_whisk/job_spec.rb +113 -0
  20. data/spec/lib/sauce_whisk/jobs_spec.rb +78 -0
  21. data/spec/lib/sauce_whisk/rest_request_builder_spec.rb +50 -0
  22. data/spec/lib/sauce_whisk/sauce_whisk_spec.rb +27 -0
  23. data/spec/spec_helper.rb +25 -0
  24. data/vendor/psych/lib/psych/class_loader.rb +101 -0
  25. data/vendor/psych/lib/psych/coder.rb +94 -0
  26. data/vendor/psych/lib/psych/core_ext.rb +35 -0
  27. data/vendor/psych/lib/psych/deprecated.rb +85 -0
  28. data/vendor/psych/lib/psych/exception.rb +13 -0
  29. data/vendor/psych/lib/psych/handler.rb +249 -0
  30. data/vendor/psych/lib/psych/handlers/document_stream.rb +22 -0
  31. data/vendor/psych/lib/psych/handlers/recorder.rb +39 -0
  32. data/vendor/psych/lib/psych/json/ruby_events.rb +19 -0
  33. data/vendor/psych/lib/psych/json/stream.rb +16 -0
  34. data/vendor/psych/lib/psych/json/tree_builder.rb +12 -0
  35. data/vendor/psych/lib/psych/json/yaml_events.rb +29 -0
  36. data/vendor/psych/lib/psych/nodes/alias.rb +18 -0
  37. data/vendor/psych/lib/psych/nodes/document.rb +60 -0
  38. data/vendor/psych/lib/psych/nodes/mapping.rb +56 -0
  39. data/vendor/psych/lib/psych/nodes/node.rb +55 -0
  40. data/vendor/psych/lib/psych/nodes/scalar.rb +67 -0
  41. data/vendor/psych/lib/psych/nodes/sequence.rb +81 -0
  42. data/vendor/psych/lib/psych/nodes/stream.rb +37 -0
  43. data/vendor/psych/lib/psych/nodes.rb +77 -0
  44. data/vendor/psych/lib/psych/omap.rb +4 -0
  45. data/vendor/psych/lib/psych/parser.rb +51 -0
  46. data/vendor/psych/lib/psych/scalar_scanner.rb +149 -0
  47. data/vendor/psych/lib/psych/set.rb +4 -0
  48. data/vendor/psych/lib/psych/stream.rb +37 -0
  49. data/vendor/psych/lib/psych/streaming.rb +27 -0
  50. data/vendor/psych/lib/psych/syntax_error.rb +21 -0
  51. data/vendor/psych/lib/psych/tree_builder.rb +96 -0
  52. data/vendor/psych/lib/psych/visitors/depth_first.rb +26 -0
  53. data/vendor/psych/lib/psych/visitors/emitter.rb +51 -0
  54. data/vendor/psych/lib/psych/visitors/json_tree.rb +24 -0
  55. data/vendor/psych/lib/psych/visitors/to_ruby.rb +372 -0
  56. data/vendor/psych/lib/psych/visitors/visitor.rb +19 -0
  57. data/vendor/psych/lib/psych/visitors/yaml_tree.rb +496 -0
  58. data/vendor/psych/lib/psych/visitors.rb +6 -0
  59. data/vendor/psych/lib/psych/y.rb +9 -0
  60. data/vendor/psych/lib/psych.bundle +0 -0
  61. data/vendor/psych/lib/psych.rb +497 -0
  62. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/Makefile +221 -0
  63. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/mkmf.log +50 -0
  64. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych.bundle +0 -0
  65. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych.o +0 -0
  66. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_emitter.o +0 -0
  67. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_parser.o +0 -0
  68. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_to_ruby.o +0 -0
  69. data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_yaml_tree.o +0 -0
  70. metadata +194 -0
@@ -0,0 +1,496 @@
1
+ require 'psych/tree_builder'
2
+ require 'psych/scalar_scanner'
3
+ require 'psych/class_loader'
4
+
5
+ module Psych
6
+ module Visitors
7
+ ###
8
+ # YAMLTree builds a YAML ast given a ruby object. For example:
9
+ #
10
+ # builder = Psych::Visitors::YAMLTree.new
11
+ # builder << { :foo => 'bar' }
12
+ # builder.tree # => #<Psych::Nodes::Stream .. }
13
+ #
14
+ class YAMLTree < Psych::Visitors::Visitor
15
+ class Registrar # :nodoc:
16
+ def initialize
17
+ @obj_to_id = {}
18
+ @obj_to_node = {}
19
+ @counter = 0
20
+ end
21
+
22
+ def register target, node
23
+ @obj_to_node[target.object_id] = node
24
+ end
25
+
26
+ def key? target
27
+ @obj_to_node.key? target.object_id
28
+ end
29
+
30
+ def id_for target
31
+ @obj_to_id[target.object_id] ||= (@counter += 1)
32
+ end
33
+
34
+ def node_for target
35
+ @obj_to_node[target.object_id]
36
+ end
37
+ end
38
+
39
+ attr_reader :started, :finished
40
+ alias :finished? :finished
41
+ alias :started? :started
42
+
43
+ def self.create options = {}, emitter = nil
44
+ emitter ||= TreeBuilder.new
45
+ class_loader = ClassLoader.new
46
+ ss = ScalarScanner.new class_loader
47
+ new(emitter, ss, options)
48
+ end
49
+
50
+ def initialize emitter, ss, options
51
+ super()
52
+ @started = false
53
+ @finished = false
54
+ @emitter = emitter
55
+ @st = Registrar.new
56
+ @ss = ss
57
+ @options = options
58
+ @coders = []
59
+
60
+ @dispatch_cache = Hash.new do |h,klass|
61
+ method = "visit_#{(klass.name || '').split('::').join('_')}"
62
+
63
+ method = respond_to?(method) ? method : h[klass.superclass]
64
+
65
+ raise(TypeError, "Can't dump #{target.class}") unless method
66
+
67
+ h[klass] = method
68
+ end
69
+ end
70
+
71
+ def start encoding = Nodes::Stream::UTF8
72
+ @emitter.start_stream(encoding).tap do
73
+ @started = true
74
+ end
75
+ end
76
+
77
+ def finish
78
+ @emitter.end_stream.tap do
79
+ @finished = true
80
+ end
81
+ end
82
+
83
+ def tree
84
+ finish unless finished?
85
+ @emitter.root
86
+ end
87
+
88
+ def push object
89
+ start unless started?
90
+ version = []
91
+ version = [1,1] if @options[:header]
92
+
93
+ case @options[:version]
94
+ when Array
95
+ version = @options[:version]
96
+ when String
97
+ version = @options[:version].split('.').map { |x| x.to_i }
98
+ else
99
+ version = [1,1]
100
+ end if @options.key? :version
101
+
102
+ @emitter.start_document version, [], false
103
+ accept object
104
+ @emitter.end_document !@emitter.streaming?
105
+ end
106
+ alias :<< :push
107
+
108
+ def accept target
109
+ # return any aliases we find
110
+ if @st.key? target
111
+ oid = @st.id_for target
112
+ node = @st.node_for target
113
+ anchor = oid.to_s
114
+ node.anchor = anchor
115
+ return @emitter.alias anchor
116
+ end
117
+
118
+ if target.respond_to?(:to_yaml)
119
+ begin
120
+ loc = target.method(:to_yaml).source_location.first
121
+ if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/
122
+ unless target.respond_to?(:encode_with)
123
+ if $VERBOSE
124
+ warn "implementing to_yaml is deprecated, please implement \"encode_with\""
125
+ end
126
+
127
+ target.to_yaml(:nodump => true)
128
+ end
129
+ end
130
+ rescue
131
+ # public_method or source_location might be overridden,
132
+ # and it's OK to skip it since it's only to emit a warning
133
+ end
134
+ end
135
+
136
+ if target.respond_to?(:encode_with)
137
+ dump_coder target
138
+ else
139
+ send(@dispatch_cache[target.class], target)
140
+ end
141
+ end
142
+
143
+ def visit_Psych_Omap o
144
+ seq = @emitter.start_sequence(nil, '!omap', false, Nodes::Sequence::BLOCK)
145
+ register(o, seq)
146
+
147
+ o.each { |k,v| visit_Hash k => v }
148
+ @emitter.end_sequence
149
+ end
150
+
151
+ def visit_Object o
152
+ tag = Psych.dump_tags[o.class]
153
+ unless tag
154
+ klass = o.class == Object ? nil : o.class.name
155
+ tag = ['!ruby/object', klass].compact.join(':')
156
+ end
157
+
158
+ map = @emitter.start_mapping(nil, tag, false, Nodes::Mapping::BLOCK)
159
+ register(o, map)
160
+
161
+ dump_ivars o
162
+ @emitter.end_mapping
163
+ end
164
+
165
+ def visit_Struct o
166
+ tag = ['!ruby/struct', o.class.name].compact.join(':')
167
+
168
+ register o, @emitter.start_mapping(nil, tag, false, Nodes::Mapping::BLOCK)
169
+ o.members.each do |member|
170
+ @emitter.scalar member.to_s, nil, nil, true, false, Nodes::Scalar::ANY
171
+ accept o[member]
172
+ end
173
+
174
+ dump_ivars o
175
+
176
+ @emitter.end_mapping
177
+ end
178
+
179
+ def visit_Exception o
180
+ tag = ['!ruby/exception', o.class.name].join ':'
181
+
182
+ @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
183
+
184
+ {
185
+ 'message' => private_iv_get(o, 'mesg'),
186
+ 'backtrace' => private_iv_get(o, 'backtrace'),
187
+ }.each do |k,v|
188
+ next unless v
189
+ @emitter.scalar k, nil, nil, true, false, Nodes::Scalar::ANY
190
+ accept v
191
+ end
192
+
193
+ dump_ivars o
194
+
195
+ @emitter.end_mapping
196
+ end
197
+
198
+ def visit_Regexp o
199
+ register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY)
200
+ end
201
+
202
+ def visit_DateTime o
203
+ formatted = format_time o.to_time
204
+ tag = '!ruby/object:DateTime'
205
+ register o, @emitter.scalar(formatted, nil, tag, false, false, Nodes::Scalar::ANY)
206
+ end
207
+
208
+ def visit_Time o
209
+ formatted = format_time o
210
+ @emitter.scalar formatted, nil, nil, true, false, Nodes::Scalar::ANY
211
+ end
212
+
213
+ def visit_Rational o
214
+ register o, @emitter.start_mapping(nil, '!ruby/object:Rational', false, Nodes::Mapping::BLOCK)
215
+
216
+ [
217
+ 'denominator', o.denominator.to_s,
218
+ 'numerator', o.numerator.to_s
219
+ ].each do |m|
220
+ @emitter.scalar m, nil, nil, true, false, Nodes::Scalar::ANY
221
+ end
222
+
223
+ @emitter.end_mapping
224
+ end
225
+
226
+ def visit_Complex o
227
+ register o, @emitter.start_mapping(nil, '!ruby/object:Complex', false, Nodes::Mapping::BLOCK)
228
+
229
+ ['real', o.real.to_s, 'image', o.imag.to_s].each do |m|
230
+ @emitter.scalar m, nil, nil, true, false, Nodes::Scalar::ANY
231
+ end
232
+
233
+ @emitter.end_mapping
234
+ end
235
+
236
+ def visit_Integer o
237
+ @emitter.scalar o.to_s, nil, nil, true, false, Nodes::Scalar::ANY
238
+ end
239
+ alias :visit_TrueClass :visit_Integer
240
+ alias :visit_FalseClass :visit_Integer
241
+ alias :visit_Date :visit_Integer
242
+
243
+ def visit_Float o
244
+ if o.nan?
245
+ @emitter.scalar '.nan', nil, nil, true, false, Nodes::Scalar::ANY
246
+ elsif o.infinite?
247
+ @emitter.scalar((o.infinite? > 0 ? '.inf' : '-.inf'),
248
+ nil, nil, true, false, Nodes::Scalar::ANY)
249
+ else
250
+ @emitter.scalar o.to_s, nil, nil, true, false, Nodes::Scalar::ANY
251
+ end
252
+ end
253
+
254
+ def visit_BigDecimal o
255
+ @emitter.scalar o._dump, nil, '!ruby/object:BigDecimal', false, false, Nodes::Scalar::ANY
256
+ end
257
+
258
+ def binary? string
259
+ (string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?) ||
260
+ string.index("\x00") ||
261
+ string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.length) > 0.3 ||
262
+ string.class != String
263
+ end
264
+ private :binary?
265
+
266
+ def visit_String o
267
+ plain = true
268
+ quote = true
269
+ style = Nodes::Scalar::PLAIN
270
+ tag = nil
271
+ str = o
272
+
273
+ if binary?(o)
274
+ str = [o].pack('m').chomp
275
+ tag = '!binary' # FIXME: change to below when syck is removed
276
+ #tag = 'tag:yaml.org,2002:binary'
277
+ style = Nodes::Scalar::LITERAL
278
+ plain = false
279
+ quote = false
280
+ elsif o =~ /\n/
281
+ style = Nodes::Scalar::LITERAL
282
+ else
283
+ unless String === @ss.tokenize(o)
284
+ style = Nodes::Scalar::SINGLE_QUOTED
285
+ end
286
+ end
287
+
288
+ ivars = find_ivars o
289
+
290
+ if ivars.empty?
291
+ unless o.class == ::String
292
+ tag = "!ruby/string:#{o.class}"
293
+ end
294
+ @emitter.scalar str, nil, tag, plain, quote, style
295
+ else
296
+ maptag = '!ruby/string'
297
+ maptag << ":#{o.class}" unless o.class == ::String
298
+
299
+ register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
300
+ @emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
301
+ @emitter.scalar str, nil, tag, plain, quote, style
302
+
303
+ dump_ivars o
304
+
305
+ @emitter.end_mapping
306
+ end
307
+ end
308
+
309
+ def visit_Module o
310
+ raise TypeError, "can't dump anonymous module: #{o}" unless o.name
311
+ register o, @emitter.scalar(o.name, nil, '!ruby/module', false, false, Nodes::Scalar::SINGLE_QUOTED)
312
+ end
313
+
314
+ def visit_Class o
315
+ raise TypeError, "can't dump anonymous class: #{o}" unless o.name
316
+ register o, @emitter.scalar(o.name, nil, '!ruby/class', false, false, Nodes::Scalar::SINGLE_QUOTED)
317
+ end
318
+
319
+ def visit_Range o
320
+ register o, @emitter.start_mapping(nil, '!ruby/range', false, Nodes::Mapping::BLOCK)
321
+ ['begin', o.begin, 'end', o.end, 'excl', o.exclude_end?].each do |m|
322
+ accept m
323
+ end
324
+ @emitter.end_mapping
325
+ end
326
+
327
+ def visit_Hash o
328
+ tag = o.class == ::Hash ? nil : "!ruby/hash:#{o.class}"
329
+ implicit = !tag
330
+
331
+ register(o, @emitter.start_mapping(nil, tag, implicit, Psych::Nodes::Mapping::BLOCK))
332
+
333
+ o.each do |k,v|
334
+ accept k
335
+ accept v
336
+ end
337
+
338
+ @emitter.end_mapping
339
+ end
340
+
341
+ def visit_Psych_Set o
342
+ register(o, @emitter.start_mapping(nil, '!set', false, Psych::Nodes::Mapping::BLOCK))
343
+
344
+ o.each do |k,v|
345
+ accept k
346
+ accept v
347
+ end
348
+
349
+ @emitter.end_mapping
350
+ end
351
+
352
+ def visit_Array o
353
+ if o.class == ::Array
354
+ register o, @emitter.start_sequence(nil, nil, true, Nodes::Sequence::BLOCK)
355
+ o.each { |c| accept c }
356
+ @emitter.end_sequence
357
+ else
358
+ visit_array_subclass o
359
+ end
360
+ end
361
+
362
+ def visit_NilClass o
363
+ @emitter.scalar('', nil, 'tag:yaml.org,2002:null', true, false, Nodes::Scalar::ANY)
364
+ end
365
+
366
+ def visit_Symbol o
367
+ @emitter.scalar ":#{o}", nil, nil, true, false, Nodes::Scalar::ANY
368
+ end
369
+
370
+ private
371
+ def visit_array_subclass o
372
+ tag = "!ruby/array:#{o.class}"
373
+ if o.instance_variables.empty?
374
+ node = @emitter.start_sequence(nil, tag, false, Nodes::Sequence::BLOCK)
375
+ register o, node
376
+ o.each { |c| accept c }
377
+ @emitter.end_sequence
378
+ else
379
+ node = @emitter.start_mapping(nil, tag, false, Nodes::Sequence::BLOCK)
380
+ register o, node
381
+
382
+ # Dump the internal list
383
+ accept 'internal'
384
+ @emitter.start_sequence(nil, nil, true, Nodes::Sequence::BLOCK)
385
+ o.each { |c| accept c }
386
+ @emitter.end_sequence
387
+
388
+ # Dump the ivars
389
+ accept 'ivars'
390
+ @emitter.start_mapping(nil, nil, true, Nodes::Sequence::BLOCK)
391
+ o.instance_variables.each do |ivar|
392
+ accept ivar
393
+ accept o.instance_variable_get ivar
394
+ end
395
+ @emitter.end_mapping
396
+
397
+ @emitter.end_mapping
398
+ end
399
+ end
400
+
401
+ def dump_list o
402
+ end
403
+
404
+ # '%:z' was no defined until 1.9.3
405
+ if RUBY_VERSION < '1.9.3'
406
+ def format_time time
407
+ formatted = time.strftime("%Y-%m-%d %H:%M:%S.%9N")
408
+
409
+ if time.utc?
410
+ formatted += " Z"
411
+ else
412
+ zone = time.strftime('%z')
413
+ formatted += " #{zone[0,3]}:#{zone[3,5]}"
414
+ end
415
+
416
+ formatted
417
+ end
418
+ else
419
+ def format_time time
420
+ if time.utc?
421
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
422
+ else
423
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
424
+ end
425
+ end
426
+ end
427
+
428
+ # FIXME: remove this method once "to_yaml_properties" is removed
429
+ def find_ivars target
430
+ begin
431
+ loc = target.method(:to_yaml_properties).source_location.first
432
+ unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb')
433
+ if $VERBOSE
434
+ warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\""
435
+ end
436
+ return target.to_yaml_properties
437
+ end
438
+ rescue
439
+ # public_method or source_location might be overridden,
440
+ # and it's OK to skip it since it's only to emit a warning.
441
+ end
442
+
443
+ target.instance_variables
444
+ end
445
+
446
+ def register target, yaml_obj
447
+ @st.register target, yaml_obj
448
+ yaml_obj
449
+ end
450
+
451
+ def dump_coder o
452
+ @coders << o
453
+ tag = Psych.dump_tags[o.class]
454
+ unless tag
455
+ klass = o.class == Object ? nil : o.class.name
456
+ tag = ['!ruby/object', klass].compact.join(':')
457
+ end
458
+
459
+ c = Psych::Coder.new(tag)
460
+ o.encode_with(c)
461
+ emit_coder c
462
+ end
463
+
464
+ def emit_coder c
465
+ case c.type
466
+ when :scalar
467
+ @emitter.scalar c.scalar, nil, c.tag, c.tag.nil?, false, Nodes::Scalar::ANY
468
+ when :seq
469
+ @emitter.start_sequence nil, c.tag, c.tag.nil?, Nodes::Sequence::BLOCK
470
+ c.seq.each do |thing|
471
+ accept thing
472
+ end
473
+ @emitter.end_sequence
474
+ when :map
475
+ @emitter.start_mapping nil, c.tag, c.implicit, c.style
476
+ c.map.each do |k,v|
477
+ accept k
478
+ accept v
479
+ end
480
+ @emitter.end_mapping
481
+ when :object
482
+ accept c.object
483
+ end
484
+ end
485
+
486
+ def dump_ivars target
487
+ ivars = find_ivars target
488
+
489
+ ivars.each do |iv|
490
+ @emitter.scalar("#{iv.to_s.sub(/^@/, '')}", nil, nil, true, false, Nodes::Scalar::ANY)
491
+ accept target.instance_variable_get(iv)
492
+ end
493
+ end
494
+ end
495
+ end
496
+ end
@@ -0,0 +1,6 @@
1
+ require 'psych/visitors/visitor'
2
+ require 'psych/visitors/to_ruby'
3
+ require 'psych/visitors/emitter'
4
+ require 'psych/visitors/yaml_tree'
5
+ require 'psych/visitors/json_tree'
6
+ require 'psych/visitors/depth_first'
@@ -0,0 +1,9 @@
1
+ module Kernel
2
+ ###
3
+ # An alias for Psych.dump_stream meant to be used with IRB.
4
+ def y *objects
5
+ puts Psych.dump_stream(*objects)
6
+ end
7
+ private :y
8
+ end
9
+
Binary file