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,101 @@
1
+ require 'psych/omap'
2
+ require 'psych/set'
3
+
4
+ module Psych
5
+ class ClassLoader # :nodoc:
6
+ BIG_DECIMAL = 'BigDecimal'
7
+ COMPLEX = 'Complex'
8
+ DATE = 'Date'
9
+ DATE_TIME = 'DateTime'
10
+ EXCEPTION = 'Exception'
11
+ OBJECT = 'Object'
12
+ PSYCH_OMAP = 'Psych::Omap'
13
+ PSYCH_SET = 'Psych::Set'
14
+ RANGE = 'Range'
15
+ RATIONAL = 'Rational'
16
+ REGEXP = 'Regexp'
17
+ STRUCT = 'Struct'
18
+ SYMBOL = 'Symbol'
19
+
20
+ def initialize
21
+ @cache = CACHE.dup
22
+ end
23
+
24
+ def load klassname
25
+ return nil if !klassname || klassname.empty?
26
+
27
+ find klassname
28
+ end
29
+
30
+ def symbolize sym
31
+ symbol
32
+ sym.to_sym
33
+ end
34
+
35
+ constants.each do |const|
36
+ konst = const_get const
37
+ define_method(const.to_s.downcase) do
38
+ load konst
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def find klassname
45
+ @cache[klassname] ||= resolve(klassname)
46
+ end
47
+
48
+ def resolve klassname
49
+ name = klassname
50
+ retried = false
51
+
52
+ begin
53
+ path2class(name)
54
+ rescue ArgumentError, NameError => ex
55
+ unless retried
56
+ name = "Struct::#{name}"
57
+ retried = ex
58
+ retry
59
+ end
60
+ raise retried
61
+ end
62
+ end
63
+
64
+ CACHE = Hash[constants.map { |const|
65
+ val = const_get const
66
+ begin
67
+ [val, ::Object.const_get(val)]
68
+ rescue
69
+ nil
70
+ end
71
+ }.compact]
72
+
73
+ class Restricted < ClassLoader
74
+ def initialize classes, symbols
75
+ @classes = classes
76
+ @symbols = symbols
77
+ super()
78
+ end
79
+
80
+ def symbolize sym
81
+ return super if @symbols.empty?
82
+
83
+ if @symbols.include? sym
84
+ super
85
+ else
86
+ raise DisallowedClass, 'Symbol'
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ def find klassname
93
+ if @classes.include? klassname
94
+ super
95
+ else
96
+ raise DisallowedClass, klassname
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,94 @@
1
+ module Psych
2
+ ###
3
+ # If an object defines +encode_with+, then an instance of Psych::Coder will
4
+ # be passed to the method when the object is being serialized. The Coder
5
+ # automatically assumes a Psych::Nodes::Mapping is being emitted. Other
6
+ # objects like Sequence and Scalar may be emitted if +seq=+ or +scalar=+ are
7
+ # called, respectively.
8
+ class Coder
9
+ attr_accessor :tag, :style, :implicit, :object
10
+ attr_reader :type, :seq
11
+
12
+ def initialize tag
13
+ @map = {}
14
+ @seq = []
15
+ @implicit = false
16
+ @type = :map
17
+ @tag = tag
18
+ @style = Psych::Nodes::Mapping::BLOCK
19
+ @scalar = nil
20
+ @object = nil
21
+ end
22
+
23
+ def scalar *args
24
+ if args.length > 0
25
+ warn "#{caller[0]}: Coder#scalar(a,b,c) is deprecated" if $VERBOSE
26
+ @tag, @scalar, _ = args
27
+ @type = :scalar
28
+ end
29
+ @scalar
30
+ end
31
+
32
+ # Emit a map. The coder will be yielded to the block.
33
+ def map tag = @tag, style = @style
34
+ @tag = tag
35
+ @style = style
36
+ yield self if block_given?
37
+ @map
38
+ end
39
+
40
+ # Emit a scalar with +value+ and +tag+
41
+ def represent_scalar tag, value
42
+ self.tag = tag
43
+ self.scalar = value
44
+ end
45
+
46
+ # Emit a sequence with +list+ and +tag+
47
+ def represent_seq tag, list
48
+ @tag = tag
49
+ self.seq = list
50
+ end
51
+
52
+ # Emit a sequence with +map+ and +tag+
53
+ def represent_map tag, map
54
+ @tag = tag
55
+ self.map = map
56
+ end
57
+
58
+ # Emit an arbitrary object +obj+ and +tag+
59
+ def represent_object tag, obj
60
+ @tag = tag
61
+ @type = :object
62
+ @object = obj
63
+ end
64
+
65
+ # Emit a scalar with +value+
66
+ def scalar= value
67
+ @type = :scalar
68
+ @scalar = value
69
+ end
70
+
71
+ # Emit a map with +value+
72
+ def map= map
73
+ @type = :map
74
+ @map = map
75
+ end
76
+
77
+ def []= k, v
78
+ @type = :map
79
+ @map[k] = v
80
+ end
81
+ alias :add :[]=
82
+
83
+ def [] k
84
+ @type = :map
85
+ @map[k]
86
+ end
87
+
88
+ # Emit a sequence of +list+
89
+ def seq= list
90
+ @type = :seq
91
+ @seq = list
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,35 @@
1
+ class Object
2
+ def self.yaml_tag url
3
+ Psych.add_tag(url, self)
4
+ end
5
+
6
+ # FIXME: rename this to "to_yaml" when syck is removed
7
+
8
+ ###
9
+ # call-seq: to_yaml(options = {})
10
+ #
11
+ # Convert an object to YAML. See Psych.dump for more information on the
12
+ # available +options+.
13
+ def psych_to_yaml options = {}
14
+ Psych.dump self, options
15
+ end
16
+ remove_method :to_yaml rescue nil
17
+ alias :to_yaml :psych_to_yaml
18
+ end
19
+
20
+ class Module
21
+ def psych_yaml_as url
22
+ return if caller[0].end_with?('rubytypes.rb')
23
+ if $VERBOSE
24
+ warn "#{caller[0]}: yaml_as is deprecated, please use yaml_tag"
25
+ end
26
+ Psych.add_tag(url, self)
27
+ end
28
+
29
+ remove_method :yaml_as rescue nil
30
+ alias :yaml_as :psych_yaml_as
31
+ end
32
+
33
+ if defined?(::IRB)
34
+ require 'psych/y'
35
+ end
@@ -0,0 +1,85 @@
1
+ require 'date'
2
+
3
+ module Psych
4
+ DEPRECATED = __FILE__ # :nodoc:
5
+
6
+ module DeprecatedMethods # :nodoc:
7
+ attr_accessor :taguri
8
+ attr_accessor :to_yaml_style
9
+ end
10
+
11
+ def self.quick_emit thing, opts = {}, &block # :nodoc:
12
+ warn "#{caller[0]}: YAML.quick_emit is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
13
+ target = eval 'self', block.binding
14
+ target.extend DeprecatedMethods
15
+ metaclass = class << target; self; end
16
+ metaclass.send(:define_method, :encode_with) do |coder|
17
+ target.taguri = coder.tag
18
+ target.to_yaml_style = coder.style
19
+ block.call coder
20
+ end
21
+ target.psych_to_yaml unless opts[:nodump]
22
+ end
23
+
24
+ # This method is deprecated, use Psych.load_stream instead.
25
+ def self.load_documents yaml, &block
26
+ if $VERBOSE
27
+ warn "#{caller[0]}: load_documents is deprecated, use load_stream"
28
+ end
29
+ list = load_stream yaml
30
+ return list unless block_given?
31
+ list.each(&block)
32
+ end
33
+
34
+ def self.detect_implicit thing
35
+ warn "#{caller[0]}: detect_implicit is deprecated" if $VERBOSE
36
+ return '' unless String === thing
37
+ return 'null' if '' == thing
38
+ ss = ScalarScanner.new(ClassLoader.new)
39
+ ss.tokenize(thing).class.name.downcase
40
+ end
41
+
42
+ def self.add_ruby_type type_tag, &block
43
+ warn "#{caller[0]}: add_ruby_type is deprecated, use add_domain_type" if $VERBOSE
44
+ domain = 'ruby.yaml.org,2002'
45
+ key = ['tag', domain, type_tag].join ':'
46
+ @domain_types[key] = [key, block]
47
+ end
48
+
49
+ def self.add_private_type type_tag, &block
50
+ warn "#{caller[0]}: add_private_type is deprecated, use add_domain_type" if $VERBOSE
51
+ domain = 'x-private'
52
+ key = [domain, type_tag].join ':'
53
+ @domain_types[key] = [key, block]
54
+ end
55
+
56
+ def self.tagurize thing
57
+ warn "#{caller[0]}: add_private_type is deprecated, use add_domain_type" if $VERBOSE
58
+ return thing unless String === thing
59
+ "tag:yaml.org,2002:#{thing}"
60
+ end
61
+
62
+ def self.read_type_class type, reference
63
+ warn "#{caller[0]}: read_type_class is deprecated" if $VERBOSE
64
+ _, _, type, name = type.split ':', 4
65
+
66
+ reference = name.split('::').inject(reference) do |k,n|
67
+ k.const_get(n.to_sym)
68
+ end if name
69
+ [type, reference]
70
+ end
71
+
72
+ def self.object_maker klass, hash
73
+ warn "#{caller[0]}: object_maker is deprecated" if $VERBOSE
74
+ klass.allocate.tap do |obj|
75
+ hash.each { |k,v| obj.instance_variable_set(:"@#{k}", v) }
76
+ end
77
+ end
78
+ end
79
+
80
+ class Object
81
+ undef :to_yaml_properties rescue nil
82
+ def to_yaml_properties # :nodoc:
83
+ instance_variables
84
+ end
85
+ end
@@ -0,0 +1,13 @@
1
+ module Psych
2
+ class Exception < RuntimeError
3
+ end
4
+
5
+ class BadAlias < Exception
6
+ end
7
+
8
+ class DisallowedClass < Exception
9
+ def initialize klass_name
10
+ super "Tried to load unspecified class: #{klass_name}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,249 @@
1
+ module Psych
2
+ ###
3
+ # Psych::Handler is an abstract base class that defines the events used
4
+ # when dealing with Psych::Parser. Clients who want to use Psych::Parser
5
+ # should implement a class that inherits from Psych::Handler and define
6
+ # events that they can handle.
7
+ #
8
+ # Psych::Handler defines all events that Psych::Parser can possibly send to
9
+ # event handlers.
10
+ #
11
+ # See Psych::Parser for more details
12
+ class Handler
13
+ ###
14
+ # Configuration options for dumping YAML.
15
+ class DumperOptions
16
+ attr_accessor :line_width, :indentation, :canonical
17
+
18
+ def initialize
19
+ @line_width = 0
20
+ @indentation = 2
21
+ @canonical = false
22
+ end
23
+ end
24
+
25
+ # Default dumping options
26
+ OPTIONS = DumperOptions.new
27
+
28
+ # Events that a Handler should respond to.
29
+ EVENTS = [ :alias,
30
+ :empty,
31
+ :end_document,
32
+ :end_mapping,
33
+ :end_sequence,
34
+ :end_stream,
35
+ :scalar,
36
+ :start_document,
37
+ :start_mapping,
38
+ :start_sequence,
39
+ :start_stream ]
40
+
41
+ ###
42
+ # Called with +encoding+ when the YAML stream starts. This method is
43
+ # called once per stream. A stream may contain multiple documents.
44
+ #
45
+ # See the constants in Psych::Parser for the possible values of +encoding+.
46
+ def start_stream encoding
47
+ end
48
+
49
+ ###
50
+ # Called when the document starts with the declared +version+,
51
+ # +tag_directives+, if the document is +implicit+.
52
+ #
53
+ # +version+ will be an array of integers indicating the YAML version being
54
+ # dealt with, +tag_directives+ is a list of tuples indicating the prefix
55
+ # and suffix of each tag, and +implicit+ is a boolean indicating whether
56
+ # the document is started implicitly.
57
+ #
58
+ # === Example
59
+ #
60
+ # Given the following YAML:
61
+ #
62
+ # %YAML 1.1
63
+ # %TAG ! tag:tenderlovemaking.com,2009:
64
+ # --- !squee
65
+ #
66
+ # The parameters for start_document must be this:
67
+ #
68
+ # version # => [1, 1]
69
+ # tag_directives # => [["!", "tag:tenderlovemaking.com,2009:"]]
70
+ # implicit # => false
71
+ def start_document version, tag_directives, implicit
72
+ end
73
+
74
+ ###
75
+ # Called with the document ends. +implicit+ is a boolean value indicating
76
+ # whether or not the document has an implicit ending.
77
+ #
78
+ # === Example
79
+ #
80
+ # Given the following YAML:
81
+ #
82
+ # ---
83
+ # hello world
84
+ #
85
+ # +implicit+ will be true. Given this YAML:
86
+ #
87
+ # ---
88
+ # hello world
89
+ # ...
90
+ #
91
+ # +implicit+ will be false.
92
+ def end_document implicit
93
+ end
94
+
95
+ ###
96
+ # Called when an alias is found to +anchor+. +anchor+ will be the name
97
+ # of the anchor found.
98
+ #
99
+ # === Example
100
+ #
101
+ # Here we have an example of an array that references itself in YAML:
102
+ #
103
+ # --- &ponies
104
+ # - first element
105
+ # - *ponies
106
+ #
107
+ # &ponies is the achor, *ponies is the alias. In this case, alias is
108
+ # called with "ponies".
109
+ def alias anchor
110
+ end
111
+
112
+ ###
113
+ # Called when a scalar +value+ is found. The scalar may have an
114
+ # +anchor+, a +tag+, be implicitly +plain+ or implicitly +quoted+
115
+ #
116
+ # +value+ is the string value of the scalar
117
+ # +anchor+ is an associated anchor or nil
118
+ # +tag+ is an associated tag or nil
119
+ # +plain+ is a boolean value
120
+ # +quoted+ is a boolean value
121
+ # +style+ is an integer idicating the string style
122
+ #
123
+ # See the constants in Psych::Nodes::Scalar for the possible values of
124
+ # +style+
125
+ #
126
+ # === Example
127
+ #
128
+ # Here is a YAML document that exercises most of the possible ways this
129
+ # method can be called:
130
+ #
131
+ # ---
132
+ # - !str "foo"
133
+ # - &anchor fun
134
+ # - many
135
+ # lines
136
+ # - |
137
+ # many
138
+ # newlines
139
+ #
140
+ # The above YAML document contains a list with four strings. Here are
141
+ # the parameters sent to this method in the same order:
142
+ #
143
+ # # value anchor tag plain quoted style
144
+ # ["foo", nil, "!str", false, false, 3 ]
145
+ # ["fun", "anchor", nil, true, false, 1 ]
146
+ # ["many lines", nil, nil, true, false, 1 ]
147
+ # ["many\nnewlines\n", nil, nil, false, true, 4 ]
148
+ #
149
+ def scalar value, anchor, tag, plain, quoted, style
150
+ end
151
+
152
+ ###
153
+ # Called when a sequence is started.
154
+ #
155
+ # +anchor+ is the anchor associated with the sequence or nil.
156
+ # +tag+ is the tag associated with the sequence or nil.
157
+ # +implicit+ a boolean indicating whether or not the sequence was implicitly
158
+ # started.
159
+ # +style+ is an integer indicating the list style.
160
+ #
161
+ # See the constants in Psych::Nodes::Sequence for the possible values of
162
+ # +style+.
163
+ #
164
+ # === Example
165
+ #
166
+ # Here is a YAML document that exercises most of the possible ways this
167
+ # method can be called:
168
+ #
169
+ # ---
170
+ # - !!seq [
171
+ # a
172
+ # ]
173
+ # - &pewpew
174
+ # - b
175
+ #
176
+ # The above YAML document consists of three lists, an outer list that
177
+ # contains two inner lists. Here is a matrix of the parameters sent
178
+ # to represent these lists:
179
+ #
180
+ # # anchor tag implicit style
181
+ # [nil, nil, true, 1 ]
182
+ # [nil, "tag:yaml.org,2002:seq", false, 2 ]
183
+ # ["pewpew", nil, true, 1 ]
184
+
185
+ def start_sequence anchor, tag, implicit, style
186
+ end
187
+
188
+ ###
189
+ # Called when a sequence ends.
190
+ def end_sequence
191
+ end
192
+
193
+ ###
194
+ # Called when a map starts.
195
+ #
196
+ # +anchor+ is the anchor associated with the map or +nil+.
197
+ # +tag+ is the tag associated with the map or +nil+.
198
+ # +implicit+ is a boolean indicating whether or not the map was implicitly
199
+ # started.
200
+ # +style+ is an integer indicating the mapping style.
201
+ #
202
+ # See the constants in Psych::Nodes::Mapping for the possible values of
203
+ # +style+.
204
+ #
205
+ # === Example
206
+ #
207
+ # Here is a YAML document that exercises most of the possible ways this
208
+ # method can be called:
209
+ #
210
+ # ---
211
+ # k: !!map { hello: world }
212
+ # v: &pewpew
213
+ # hello: world
214
+ #
215
+ # The above YAML document consists of three maps, an outer map that contains
216
+ # two inner maps. Below is a matrix of the parameters sent in order to
217
+ # represent these three maps:
218
+ #
219
+ # # anchor tag implicit style
220
+ # [nil, nil, true, 1 ]
221
+ # [nil, "tag:yaml.org,2002:map", false, 2 ]
222
+ # ["pewpew", nil, true, 1 ]
223
+
224
+ def start_mapping anchor, tag, implicit, style
225
+ end
226
+
227
+ ###
228
+ # Called when a map ends
229
+ def end_mapping
230
+ end
231
+
232
+ ###
233
+ # Called when an empty event happens. (Which, as far as I can tell, is
234
+ # never).
235
+ def empty
236
+ end
237
+
238
+ ###
239
+ # Called when the YAML stream ends
240
+ def end_stream
241
+ end
242
+
243
+ ###
244
+ # Is this handler a streaming handler?
245
+ def streaming?
246
+ false
247
+ end
248
+ end
249
+ end
@@ -0,0 +1,22 @@
1
+ require 'psych/tree_builder'
2
+
3
+ module Psych
4
+ module Handlers
5
+ class DocumentStream < Psych::TreeBuilder # :nodoc:
6
+ def initialize &block
7
+ super
8
+ @block = block
9
+ end
10
+
11
+ def start_document version, tag_directives, implicit
12
+ n = Nodes::Document.new version, tag_directives, implicit
13
+ push n
14
+ end
15
+
16
+ def end_document implicit_end = !streaming?
17
+ @last.implicit_end = implicit_end
18
+ @block.call pop
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ require 'psych/handler'
2
+
3
+ module Psych
4
+ module Handlers
5
+ ###
6
+ # This handler will capture an event and record the event. Recorder events
7
+ # are available vial Psych::Handlers::Recorder#events.
8
+ #
9
+ # For example:
10
+ #
11
+ # recorder = Psych::Handlers::Recorder.new
12
+ # parser = Psych::Parser.new recorder
13
+ # parser.parse '--- foo'
14
+ #
15
+ # recorder.events # => [list of events]
16
+ #
17
+ # # Replay the events
18
+ #
19
+ # emitter = Psych::Emitter.new $stdout
20
+ # recorder.events.each do |m, args|
21
+ # emitter.send m, *args
22
+ # end
23
+
24
+ class Recorder < Psych::Handler
25
+ attr_reader :events
26
+
27
+ def initialize
28
+ @events = []
29
+ super
30
+ end
31
+
32
+ EVENTS.each do |event|
33
+ define_method event do |*args|
34
+ @events << [event, args]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module Psych
2
+ module JSON
3
+ module RubyEvents # :nodoc:
4
+ def visit_Time o
5
+ formatted = format_time o
6
+ @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
7
+ end
8
+
9
+ def visit_DateTime o
10
+ visit_Time o.to_time
11
+ end
12
+
13
+ def visit_String o
14
+ @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
15
+ end
16
+ alias :visit_Symbol :visit_String
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'psych/json/ruby_events'
2
+ require 'psych/json/yaml_events'
3
+
4
+ module Psych
5
+ module JSON
6
+ class Stream < Psych::Visitors::JSONTree
7
+ include Psych::JSON::RubyEvents
8
+ include Psych::Streaming
9
+ extend Psych::Streaming::ClassMethods
10
+
11
+ class Emitter < Psych::Stream::Emitter # :nodoc:
12
+ include Psych::JSON::YAMLEvents
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require 'psych/json/yaml_events'
2
+
3
+ module Psych
4
+ module JSON
5
+ ###
6
+ # Psych::JSON::TreeBuilder is an event based AST builder. Events are sent
7
+ # to an instance of Psych::JSON::TreeBuilder and a JSON AST is constructed.
8
+ class TreeBuilder < Psych::TreeBuilder
9
+ include Psych::JSON::YAMLEvents
10
+ end
11
+ end
12
+ end