sauce_whisk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,37 @@
1
+ module Psych
2
+ ###
3
+ # Psych::Stream is a streaming YAML emitter. It will not buffer your YAML,
4
+ # but send it straight to an IO.
5
+ #
6
+ # Here is an example use:
7
+ #
8
+ # stream = Psych::Stream.new($stdout)
9
+ # stream.start
10
+ # stream.push({:foo => 'bar'})
11
+ # stream.finish
12
+ #
13
+ # YAML will be immediately emitted to $stdout with no buffering.
14
+ #
15
+ # Psych::Stream#start will take a block and ensure that Psych::Stream#finish
16
+ # is called, so you can do this form:
17
+ #
18
+ # stream = Psych::Stream.new($stdout)
19
+ # stream.start do |em|
20
+ # em.push(:foo => 'bar')
21
+ # end
22
+ #
23
+ class Stream < Psych::Visitors::YAMLTree
24
+ class Emitter < Psych::Emitter # :nodoc:
25
+ def end_document implicit_end = !streaming?
26
+ super
27
+ end
28
+
29
+ def streaming?
30
+ true
31
+ end
32
+ end
33
+
34
+ include Psych::Streaming
35
+ extend Psych::Streaming::ClassMethods
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ module Psych
2
+ module Streaming
3
+ module ClassMethods
4
+ ###
5
+ # Create a new streaming emitter. Emitter will print to +io+. See
6
+ # Psych::Stream for an example.
7
+ def new io
8
+ emitter = const_get(:Emitter).new(io)
9
+ class_loader = ClassLoader.new
10
+ ss = ScalarScanner.new class_loader
11
+ super(emitter, ss, {})
12
+ end
13
+ end
14
+
15
+ ###
16
+ # Start streaming using +encoding+
17
+ def start encoding = Nodes::Stream::UTF8
18
+ super.tap { yield self if block_given? }
19
+ ensure
20
+ finish if block_given?
21
+ end
22
+
23
+ private
24
+ def register target, obj
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ require 'psych/exception'
2
+
3
+ module Psych
4
+ class SyntaxError < Psych::Exception
5
+ attr_reader :file, :line, :column, :offset, :problem, :context
6
+
7
+ def initialize file, line, col, offset, problem, context
8
+ err = [problem, context].compact.join ' '
9
+ filename = file || '<unknown>'
10
+ message = "(%s): %s at line %d column %d" % [filename, err, line, col]
11
+
12
+ @file = file
13
+ @line = line
14
+ @column = col
15
+ @offset = offset
16
+ @problem = problem
17
+ @context = context
18
+ super(message)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,96 @@
1
+ require 'psych/handler'
2
+
3
+ module Psych
4
+ ###
5
+ # This class works in conjunction with Psych::Parser to build an in-memory
6
+ # parse tree that represents a YAML document.
7
+ #
8
+ # == Example
9
+ #
10
+ # parser = Psych::Parser.new Psych::TreeBuilder.new
11
+ # parser.parse('--- foo')
12
+ # tree = parser.handler.root
13
+ #
14
+ # See Psych::Handler for documentation on the event methods used in this
15
+ # class.
16
+ class TreeBuilder < Psych::Handler
17
+ # Returns the root node for the built tree
18
+ attr_reader :root
19
+
20
+ # Create a new TreeBuilder instance
21
+ def initialize
22
+ @stack = []
23
+ @last = nil
24
+ @root = nil
25
+ end
26
+
27
+ %w{
28
+ Sequence
29
+ Mapping
30
+ }.each do |node|
31
+ class_eval %{
32
+ def start_#{node.downcase}(anchor, tag, implicit, style)
33
+ n = Nodes::#{node}.new(anchor, tag, implicit, style)
34
+ @last.children << n
35
+ push n
36
+ end
37
+
38
+ def end_#{node.downcase}
39
+ pop
40
+ end
41
+ }
42
+ end
43
+
44
+ ###
45
+ # Handles start_document events with +version+, +tag_directives+,
46
+ # and +implicit+ styling.
47
+ #
48
+ # See Psych::Handler#start_document
49
+ def start_document version, tag_directives, implicit
50
+ n = Nodes::Document.new version, tag_directives, implicit
51
+ @last.children << n
52
+ push n
53
+ end
54
+
55
+ ###
56
+ # Handles end_document events with +version+, +tag_directives+,
57
+ # and +implicit+ styling.
58
+ #
59
+ # See Psych::Handler#start_document
60
+ def end_document implicit_end = !streaming?
61
+ @last.implicit_end = implicit_end
62
+ pop
63
+ end
64
+
65
+ def start_stream encoding
66
+ @root = Nodes::Stream.new(encoding)
67
+ push @root
68
+ end
69
+
70
+ def end_stream
71
+ pop
72
+ end
73
+
74
+ def scalar value, anchor, tag, plain, quoted, style
75
+ s = Nodes::Scalar.new(value,anchor,tag,plain,quoted,style)
76
+ @last.children << s
77
+ s
78
+ end
79
+
80
+ def alias anchor
81
+ @last.children << Nodes::Alias.new(anchor)
82
+ end
83
+
84
+ private
85
+ def push value
86
+ @stack.push value
87
+ @last = value
88
+ end
89
+
90
+ def pop
91
+ x = @stack.pop
92
+ @last = @stack.last
93
+ x
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,26 @@
1
+ module Psych
2
+ module Visitors
3
+ class DepthFirst < Psych::Visitors::Visitor
4
+ def initialize block
5
+ @block = block
6
+ end
7
+
8
+ private
9
+
10
+ def nary o
11
+ o.children.each { |x| visit x }
12
+ @block.call o
13
+ end
14
+ alias :visit_Psych_Nodes_Stream :nary
15
+ alias :visit_Psych_Nodes_Document :nary
16
+ alias :visit_Psych_Nodes_Sequence :nary
17
+ alias :visit_Psych_Nodes_Mapping :nary
18
+
19
+ def terminal o
20
+ @block.call o
21
+ end
22
+ alias :visit_Psych_Nodes_Scalar :terminal
23
+ alias :visit_Psych_Nodes_Alias :terminal
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ module Psych
2
+ module Visitors
3
+ class Emitter < Psych::Visitors::Visitor
4
+ def initialize io, options = {}
5
+ opts = [:indentation, :canonical, :line_width].find_all { |opt|
6
+ options.key?(opt)
7
+ }
8
+
9
+ if opts.empty?
10
+ @handler = Psych::Emitter.new io
11
+ else
12
+ du = Handler::DumperOptions.new
13
+ opts.each { |option| du.send :"#{option}=", options[option] }
14
+ @handler = Psych::Emitter.new io, du
15
+ end
16
+ end
17
+
18
+ def visit_Psych_Nodes_Stream o
19
+ @handler.start_stream o.encoding
20
+ o.children.each { |c| accept c }
21
+ @handler.end_stream
22
+ end
23
+
24
+ def visit_Psych_Nodes_Document o
25
+ @handler.start_document o.version, o.tag_directives, o.implicit
26
+ o.children.each { |c| accept c }
27
+ @handler.end_document o.implicit_end
28
+ end
29
+
30
+ def visit_Psych_Nodes_Scalar o
31
+ @handler.scalar o.value, o.anchor, o.tag, o.plain, o.quoted, o.style
32
+ end
33
+
34
+ def visit_Psych_Nodes_Sequence o
35
+ @handler.start_sequence o.anchor, o.tag, o.implicit, o.style
36
+ o.children.each { |c| accept c }
37
+ @handler.end_sequence
38
+ end
39
+
40
+ def visit_Psych_Nodes_Mapping o
41
+ @handler.start_mapping o.anchor, o.tag, o.implicit, o.style
42
+ o.children.each { |c| accept c }
43
+ @handler.end_mapping
44
+ end
45
+
46
+ def visit_Psych_Nodes_Alias o
47
+ @handler.alias o.anchor
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ require 'psych/json/ruby_events'
2
+
3
+ module Psych
4
+ module Visitors
5
+ class JSONTree < YAMLTree
6
+ include Psych::JSON::RubyEvents
7
+
8
+ def self.create options = {}
9
+ emitter = Psych::JSON::TreeBuilder.new
10
+ class_loader = ClassLoader.new
11
+ ss = ScalarScanner.new class_loader
12
+ new(emitter, ss, options)
13
+ end
14
+
15
+ def accept target
16
+ if target.respond_to?(:encode_with)
17
+ dump_coder target
18
+ else
19
+ send(@dispatch_cache[target.class], target)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,372 @@
1
+ require 'psych/scalar_scanner'
2
+ require 'psych/class_loader'
3
+ require 'psych/exception'
4
+
5
+ unless defined?(Regexp::NOENCODING)
6
+ Regexp::NOENCODING = 32
7
+ end
8
+
9
+ module Psych
10
+ module Visitors
11
+ ###
12
+ # This class walks a YAML AST, converting each node to ruby
13
+ class ToRuby < Psych::Visitors::Visitor
14
+ def self.create
15
+ class_loader = ClassLoader.new
16
+ scanner = ScalarScanner.new class_loader
17
+ new(scanner, class_loader)
18
+ end
19
+
20
+ attr_reader :class_loader
21
+
22
+ def initialize ss, class_loader
23
+ super()
24
+ @st = {}
25
+ @ss = ss
26
+ @domain_types = Psych.domain_types
27
+ @class_loader = class_loader
28
+ end
29
+
30
+ def accept target
31
+ result = super
32
+ return result if @domain_types.empty? || !target.tag
33
+
34
+ key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
35
+ key = "tag:#{key}" unless key =~ /^(tag:|x-private)/
36
+
37
+ if @domain_types.key? key
38
+ value, block = @domain_types[key]
39
+ return block.call value, result
40
+ end
41
+
42
+ result
43
+ end
44
+
45
+ def deserialize o
46
+ if klass = resolve_class(Psych.load_tags[o.tag])
47
+ instance = klass.allocate
48
+
49
+ if instance.respond_to?(:init_with)
50
+ coder = Psych::Coder.new(o.tag)
51
+ coder.scalar = o.value
52
+ instance.init_with coder
53
+ end
54
+
55
+ return instance
56
+ end
57
+
58
+ return o.value if o.quoted
59
+ return @ss.tokenize(o.value) unless o.tag
60
+
61
+ case o.tag
62
+ when '!binary', 'tag:yaml.org,2002:binary'
63
+ o.value.unpack('m').first
64
+ when /^!(?:str|ruby\/string)(?::(.*))?/, 'tag:yaml.org,2002:str'
65
+ klass = resolve_class($1)
66
+ if klass
67
+ klass.allocate.replace o.value
68
+ else
69
+ o.value
70
+ end
71
+ when '!ruby/object:BigDecimal'
72
+ require 'bigdecimal'
73
+ class_loader.big_decimal._load o.value
74
+ when "!ruby/object:DateTime"
75
+ class_loader.date_time
76
+ require 'date'
77
+ @ss.parse_time(o.value).to_datetime
78
+ when "!ruby/object:Complex"
79
+ class_loader.complex
80
+ Complex(o.value)
81
+ when "!ruby/object:Rational"
82
+ class_loader.rational
83
+ Rational(o.value)
84
+ when "!ruby/class", "!ruby/module"
85
+ resolve_class o.value
86
+ when "tag:yaml.org,2002:float", "!float"
87
+ Float(@ss.tokenize(o.value))
88
+ when "!ruby/regexp"
89
+ klass = class_loader.regexp
90
+ o.value =~ /^\/(.*)\/([mixn]*)$/
91
+ source = $1
92
+ options = 0
93
+ lang = nil
94
+ ($2 || '').split('').each do |option|
95
+ case option
96
+ when 'x' then options |= Regexp::EXTENDED
97
+ when 'i' then options |= Regexp::IGNORECASE
98
+ when 'm' then options |= Regexp::MULTILINE
99
+ when 'n' then options |= Regexp::NOENCODING
100
+ else lang = option
101
+ end
102
+ end
103
+ klass.new(*[source, options, lang].compact)
104
+ when "!ruby/range"
105
+ klass = class_loader.range
106
+ args = o.value.split(/([.]{2,3})/, 2).map { |s|
107
+ accept Nodes::Scalar.new(s)
108
+ }
109
+ args.push(args.delete_at(1) == '...')
110
+ klass.new(*args)
111
+ when /^!ruby\/sym(bol)?:?(.*)?$/
112
+ class_loader.symbolize o.value
113
+ else
114
+ @ss.tokenize o.value
115
+ end
116
+ end
117
+ private :deserialize
118
+
119
+ def visit_Psych_Nodes_Scalar o
120
+ register o, deserialize(o)
121
+ end
122
+
123
+ def visit_Psych_Nodes_Sequence o
124
+ if klass = resolve_class(Psych.load_tags[o.tag])
125
+ instance = klass.allocate
126
+
127
+ if instance.respond_to?(:init_with)
128
+ coder = Psych::Coder.new(o.tag)
129
+ coder.seq = o.children.map { |c| accept c }
130
+ instance.init_with coder
131
+ end
132
+
133
+ return instance
134
+ end
135
+
136
+ case o.tag
137
+ when nil
138
+ register_empty(o)
139
+ when '!omap', 'tag:yaml.org,2002:omap'
140
+ map = register(o, Psych::Omap.new)
141
+ o.children.each { |a|
142
+ map[accept(a.children.first)] = accept a.children.last
143
+ }
144
+ map
145
+ when /^!(?:seq|ruby\/array):(.*)$/
146
+ klass = resolve_class($1)
147
+ list = register(o, klass.allocate)
148
+ o.children.each { |c| list.push accept c }
149
+ list
150
+ else
151
+ register_empty(o)
152
+ end
153
+ end
154
+
155
+ def visit_Psych_Nodes_Mapping o
156
+ if Psych.load_tags[o.tag]
157
+ return revive(resolve_class(Psych.load_tags[o.tag]), o)
158
+ end
159
+ return revive_hash({}, o) unless o.tag
160
+
161
+ case o.tag
162
+ when /^!ruby\/struct:?(.*)?$/
163
+ klass = resolve_class($1) if $1
164
+
165
+ if klass
166
+ s = register(o, klass.allocate)
167
+
168
+ members = {}
169
+ struct_members = s.members.map { |x| class_loader.symbolize x }
170
+ o.children.each_slice(2) do |k,v|
171
+ member = accept(k)
172
+ value = accept(v)
173
+ if struct_members.include?(class_loader.symbolize(member))
174
+ s.send("#{member}=", value)
175
+ else
176
+ members[member.to_s.sub(/^@/, '')] = value
177
+ end
178
+ end
179
+ init_with(s, members, o)
180
+ else
181
+ klass = class_loader.struct
182
+ members = o.children.map { |c| accept c }
183
+ h = Hash[*members]
184
+ klass.new(*h.map { |k,v|
185
+ class_loader.symbolize k
186
+ }).new(*h.map { |k,v| v })
187
+ end
188
+
189
+ when /^!ruby\/object:?(.*)?$/
190
+ name = $1 || 'Object'
191
+
192
+ if name == 'Complex'
193
+ class_loader.complex
194
+ h = Hash[*o.children.map { |c| accept c }]
195
+ register o, Complex(h['real'], h['image'])
196
+ elsif name == 'Rational'
197
+ class_loader.rational
198
+ h = Hash[*o.children.map { |c| accept c }]
199
+ register o, Rational(h['numerator'], h['denominator'])
200
+ else
201
+ obj = revive((resolve_class(name) || class_loader.object), o)
202
+ obj
203
+ end
204
+
205
+ when /^!(?:str|ruby\/string)(?::(.*))?/, 'tag:yaml.org,2002:str'
206
+ klass = resolve_class($1)
207
+ members = {}
208
+ string = nil
209
+
210
+ o.children.each_slice(2) do |k,v|
211
+ key = accept k
212
+ value = accept v
213
+
214
+ if key == 'str'
215
+ if klass
216
+ string = klass.allocate.replace value
217
+ else
218
+ string = value
219
+ end
220
+ register(o, string)
221
+ else
222
+ members[key] = value
223
+ end
224
+ end
225
+ init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
226
+ when /^!ruby\/array:(.*)$/
227
+ klass = resolve_class($1)
228
+ list = register(o, klass.allocate)
229
+
230
+ members = Hash[o.children.map { |c| accept c }.each_slice(2).to_a]
231
+ list.replace members['internal']
232
+
233
+ members['ivars'].each do |ivar, v|
234
+ list.instance_variable_set ivar, v
235
+ end
236
+ list
237
+
238
+ when '!ruby/range'
239
+ klass = class_loader.range
240
+ h = Hash[*o.children.map { |c| accept c }]
241
+ register o, klass.new(h['begin'], h['end'], h['excl'])
242
+
243
+ when /^!ruby\/exception:?(.*)?$/
244
+ h = Hash[*o.children.map { |c| accept c }]
245
+
246
+ e = build_exception((resolve_class($1) || class_loader.exception),
247
+ h.delete('message'))
248
+ init_with(e, h, o)
249
+
250
+ when '!set', 'tag:yaml.org,2002:set'
251
+ set = class_loader.psych_set.new
252
+ @st[o.anchor] = set if o.anchor
253
+ o.children.each_slice(2) do |k,v|
254
+ set[accept(k)] = accept(v)
255
+ end
256
+ set
257
+
258
+ when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
259
+ revive_hash resolve_class($1).new, o
260
+
261
+ when '!omap', 'tag:yaml.org,2002:omap'
262
+ map = register(o, class_loader.psych_omap.new)
263
+ o.children.each_slice(2) do |l,r|
264
+ map[accept(l)] = accept r
265
+ end
266
+ map
267
+
268
+ else
269
+ revive_hash({}, o)
270
+ end
271
+ end
272
+
273
+ def visit_Psych_Nodes_Document o
274
+ accept o.root
275
+ end
276
+
277
+ def visit_Psych_Nodes_Stream o
278
+ o.children.map { |c| accept c }
279
+ end
280
+
281
+ def visit_Psych_Nodes_Alias o
282
+ @st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
283
+ end
284
+
285
+ private
286
+ def register node, object
287
+ @st[node.anchor] = object if node.anchor
288
+ object
289
+ end
290
+
291
+ def register_empty object
292
+ list = register(object, [])
293
+ object.children.each { |c| list.push accept c }
294
+ list
295
+ end
296
+
297
+ def revive_hash hash, o
298
+ @st[o.anchor] = hash if o.anchor
299
+
300
+ o.children.each_slice(2) { |k,v|
301
+ key = accept(k)
302
+ val = accept(v)
303
+
304
+ if key == '<<'
305
+ case v
306
+ when Nodes::Alias
307
+ begin
308
+ hash.merge! val
309
+ rescue TypeError
310
+ hash[key] = val
311
+ end
312
+ when Nodes::Sequence
313
+ begin
314
+ h = {}
315
+ val.reverse_each do |value|
316
+ h.merge! value
317
+ end
318
+ hash.merge! h
319
+ rescue TypeError
320
+ hash[key] = val
321
+ end
322
+ else
323
+ hash[key] = val
324
+ end
325
+ else
326
+ hash[key] = val
327
+ end
328
+
329
+ }
330
+ hash
331
+ end
332
+
333
+ def merge_key hash, key, val
334
+ end
335
+
336
+ def revive klass, node
337
+ s = klass.allocate
338
+ @st[node.anchor] = s if node.anchor
339
+ h = Hash[*node.children.map { |c| accept c }]
340
+ init_with(s, h, node)
341
+ end
342
+
343
+ def init_with o, h, node
344
+ c = Psych::Coder.new(node.tag)
345
+ c.map = h
346
+
347
+ if o.respond_to?(:init_with)
348
+ o.init_with c
349
+ elsif o.respond_to?(:yaml_initialize)
350
+ if $VERBOSE
351
+ warn "Implementing #{o.class}#yaml_initialize is deprecated, please implement \"init_with(coder)\""
352
+ end
353
+ o.yaml_initialize c.tag, c.map
354
+ else
355
+ h.each { |k,v| o.instance_variable_set(:"@#{k}", v) }
356
+ end
357
+ o
358
+ end
359
+
360
+ # Convert +klassname+ to a Class
361
+ def resolve_class klassname
362
+ class_loader.load klassname
363
+ end
364
+ end
365
+
366
+ class NoAliasRuby < ToRuby
367
+ def visit_Psych_Nodes_Alias o
368
+ raise BadAlias, "Unknown alias: #{o.anchor}"
369
+ end
370
+ end
371
+ end
372
+ end
@@ -0,0 +1,19 @@
1
+ module Psych
2
+ module Visitors
3
+ class Visitor
4
+ def accept target
5
+ visit target
6
+ end
7
+
8
+ private
9
+
10
+ DISPATCH = Hash.new do |hash, klass|
11
+ hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
12
+ end
13
+
14
+ def visit target
15
+ send DISPATCH[target.class], target
16
+ end
17
+ end
18
+ end
19
+ end