sauce_whisk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +10 -0
- data/lib/sauce_whisk/assets.rb +25 -0
- data/lib/sauce_whisk/jobs.rb +112 -0
- data/lib/sauce_whisk/rest_request_builder.rb +29 -0
- data/lib/sauce_whisk/version.rb +3 -0
- data/lib/sauce_whisk.rb +23 -0
- data/sauce_whisk.gemspec +27 -0
- data/spec/fixtures/vcr_cassettes/assets.yml +161478 -0
- data/spec/fixtures/vcr_cassettes/jobs.yml +256 -0
- data/spec/fixtures/vcr_cassettes/no_jobs.yml +0 -0
- data/spec/fixtures/vcr_cassettes/rest_request.yml +0 -0
- data/spec/lib/sauce_whisk/asset_spec.rb +39 -0
- data/spec/lib/sauce_whisk/assets_spec.rb +27 -0
- data/spec/lib/sauce_whisk/job_spec.rb +113 -0
- data/spec/lib/sauce_whisk/jobs_spec.rb +78 -0
- data/spec/lib/sauce_whisk/rest_request_builder_spec.rb +50 -0
- data/spec/lib/sauce_whisk/sauce_whisk_spec.rb +27 -0
- data/spec/spec_helper.rb +25 -0
- data/vendor/psych/lib/psych/class_loader.rb +101 -0
- data/vendor/psych/lib/psych/coder.rb +94 -0
- data/vendor/psych/lib/psych/core_ext.rb +35 -0
- data/vendor/psych/lib/psych/deprecated.rb +85 -0
- data/vendor/psych/lib/psych/exception.rb +13 -0
- data/vendor/psych/lib/psych/handler.rb +249 -0
- data/vendor/psych/lib/psych/handlers/document_stream.rb +22 -0
- data/vendor/psych/lib/psych/handlers/recorder.rb +39 -0
- data/vendor/psych/lib/psych/json/ruby_events.rb +19 -0
- data/vendor/psych/lib/psych/json/stream.rb +16 -0
- data/vendor/psych/lib/psych/json/tree_builder.rb +12 -0
- data/vendor/psych/lib/psych/json/yaml_events.rb +29 -0
- data/vendor/psych/lib/psych/nodes/alias.rb +18 -0
- data/vendor/psych/lib/psych/nodes/document.rb +60 -0
- data/vendor/psych/lib/psych/nodes/mapping.rb +56 -0
- data/vendor/psych/lib/psych/nodes/node.rb +55 -0
- data/vendor/psych/lib/psych/nodes/scalar.rb +67 -0
- data/vendor/psych/lib/psych/nodes/sequence.rb +81 -0
- data/vendor/psych/lib/psych/nodes/stream.rb +37 -0
- data/vendor/psych/lib/psych/nodes.rb +77 -0
- data/vendor/psych/lib/psych/omap.rb +4 -0
- data/vendor/psych/lib/psych/parser.rb +51 -0
- data/vendor/psych/lib/psych/scalar_scanner.rb +149 -0
- data/vendor/psych/lib/psych/set.rb +4 -0
- data/vendor/psych/lib/psych/stream.rb +37 -0
- data/vendor/psych/lib/psych/streaming.rb +27 -0
- data/vendor/psych/lib/psych/syntax_error.rb +21 -0
- data/vendor/psych/lib/psych/tree_builder.rb +96 -0
- data/vendor/psych/lib/psych/visitors/depth_first.rb +26 -0
- data/vendor/psych/lib/psych/visitors/emitter.rb +51 -0
- data/vendor/psych/lib/psych/visitors/json_tree.rb +24 -0
- data/vendor/psych/lib/psych/visitors/to_ruby.rb +372 -0
- data/vendor/psych/lib/psych/visitors/visitor.rb +19 -0
- data/vendor/psych/lib/psych/visitors/yaml_tree.rb +496 -0
- data/vendor/psych/lib/psych/visitors.rb +6 -0
- data/vendor/psych/lib/psych/y.rb +9 -0
- data/vendor/psych/lib/psych.bundle +0 -0
- data/vendor/psych/lib/psych.rb +497 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/Makefile +221 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/mkmf.log +50 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych.bundle +0 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych.o +0 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_emitter.o +0 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_parser.o +0 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_to_ruby.o +0 -0
- data/vendor/psych/tmp/x86_64-darwin12.3.0/psych/1.9.3/psych_yaml_tree.o +0 -0
- metadata +194 -0
@@ -0,0 +1,497 @@
|
|
1
|
+
require 'psych.so'
|
2
|
+
require 'psych/nodes'
|
3
|
+
require 'psych/streaming'
|
4
|
+
require 'psych/visitors'
|
5
|
+
require 'psych/handler'
|
6
|
+
require 'psych/tree_builder'
|
7
|
+
require 'psych/parser'
|
8
|
+
require 'psych/omap'
|
9
|
+
require 'psych/set'
|
10
|
+
require 'psych/coder'
|
11
|
+
require 'psych/core_ext'
|
12
|
+
require 'psych/deprecated'
|
13
|
+
require 'psych/stream'
|
14
|
+
require 'psych/json/tree_builder'
|
15
|
+
require 'psych/json/stream'
|
16
|
+
require 'psych/handlers/document_stream'
|
17
|
+
|
18
|
+
###
|
19
|
+
# = Overview
|
20
|
+
#
|
21
|
+
# Psych is a YAML parser and emitter.
|
22
|
+
# Psych leverages libyaml [Home page: http://pyyaml.org/wiki/LibYAML]
|
23
|
+
# or [Git repo: https://github.com/zerotao/libyaml] for its YAML parsing
|
24
|
+
# and emitting capabilities. In addition to wrapping libyaml, Psych also
|
25
|
+
# knows how to serialize and de-serialize most Ruby objects to and from
|
26
|
+
# the YAML format.
|
27
|
+
#
|
28
|
+
# = I NEED TO PARSE OR EMIT YAML RIGHT NOW!
|
29
|
+
#
|
30
|
+
# # Parse some YAML
|
31
|
+
# Psych.load("--- foo") # => "foo"
|
32
|
+
#
|
33
|
+
# # Emit some YAML
|
34
|
+
# Psych.dump("foo") # => "--- foo\n...\n"
|
35
|
+
# { :a => 'b'}.to_yaml # => "---\n:a: b\n"
|
36
|
+
#
|
37
|
+
# Got more time on your hands? Keep on reading!
|
38
|
+
#
|
39
|
+
# == YAML Parsing
|
40
|
+
#
|
41
|
+
# Psych provides a range of interfaces for parsing a YAML document ranging from
|
42
|
+
# low level to high level, depending on your parsing needs. At the lowest
|
43
|
+
# level, is an event based parser. Mid level is access to the raw YAML AST,
|
44
|
+
# and at the highest level is the ability to unmarshal YAML to ruby objects.
|
45
|
+
#
|
46
|
+
# == YAML Emitting
|
47
|
+
#
|
48
|
+
# Psych provides a range of interfaces ranging from low to high level for
|
49
|
+
# producing YAML documents. Very similar to the YAML parsing interfaces, Psych
|
50
|
+
# provides at the lowest level, an event based system, mid-level is building
|
51
|
+
# a YAML AST, and the highest level is converting a Ruby object straight to
|
52
|
+
# a YAML document.
|
53
|
+
#
|
54
|
+
# == High-level API
|
55
|
+
#
|
56
|
+
# === Parsing
|
57
|
+
#
|
58
|
+
# The high level YAML parser provided by Psych simply takes YAML as input and
|
59
|
+
# returns a Ruby data structure. For information on using the high level parser
|
60
|
+
# see Psych.load
|
61
|
+
#
|
62
|
+
# ==== Reading from a string
|
63
|
+
#
|
64
|
+
# Psych.load("--- a") # => 'a'
|
65
|
+
# Psych.load("---\n - a\n - b") # => ['a', 'b']
|
66
|
+
#
|
67
|
+
# ==== Reading from a file
|
68
|
+
#
|
69
|
+
# Psych.load_file("database.yml")
|
70
|
+
#
|
71
|
+
# ==== Exception handling
|
72
|
+
#
|
73
|
+
# begin
|
74
|
+
# # The second argument chnages only the exception contents
|
75
|
+
# Psych.parse("--- `", "file.txt")
|
76
|
+
# rescue Psych::SyntaxError => ex
|
77
|
+
# ex.file # => 'file.txt'
|
78
|
+
# ex.message # => "(file.txt): found character that cannot start any token"
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# === Emitting
|
82
|
+
#
|
83
|
+
# The high level emitter has the easiest interface. Psych simply takes a Ruby
|
84
|
+
# data structure and converts it to a YAML document. See Psych.dump for more
|
85
|
+
# information on dumping a Ruby data structure.
|
86
|
+
#
|
87
|
+
# ==== Writing to a string
|
88
|
+
#
|
89
|
+
# # Dump an array, get back a YAML string
|
90
|
+
# Psych.dump(['a', 'b']) # => "---\n- a\n- b\n"
|
91
|
+
#
|
92
|
+
# # Dump an array to an IO object
|
93
|
+
# Psych.dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890>
|
94
|
+
#
|
95
|
+
# # Dump an array with indentation set
|
96
|
+
# Psych.dump(['a', ['b']], :indentation => 3) # => "---\n- a\n- - b\n"
|
97
|
+
#
|
98
|
+
# # Dump an array to an IO with indentation set
|
99
|
+
# Psych.dump(['a', ['b']], StringIO.new, :indentation => 3)
|
100
|
+
#
|
101
|
+
# ==== Writing to a file
|
102
|
+
#
|
103
|
+
# Currently there is no direct API for dumping Ruby structure to file:
|
104
|
+
#
|
105
|
+
# File.open('database.yml', 'w') do |file|
|
106
|
+
# file.write(Psych.dump(['a', 'b']))
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# == Mid-level API
|
110
|
+
#
|
111
|
+
# === Parsing
|
112
|
+
#
|
113
|
+
# Psych provides access to an AST produced from parsing a YAML document. This
|
114
|
+
# tree is built using the Psych::Parser and Psych::TreeBuilder. The AST can
|
115
|
+
# be examined and manipulated freely. Please see Psych::parse_stream,
|
116
|
+
# Psych::Nodes, and Psych::Nodes::Node for more information on dealing with
|
117
|
+
# YAML syntax trees.
|
118
|
+
#
|
119
|
+
# ==== Reading from a string
|
120
|
+
#
|
121
|
+
# # Returns Psych::Nodes::Stream
|
122
|
+
# Psych.parse_stream("---\n - a\n - b")
|
123
|
+
#
|
124
|
+
# # Returns Psych::Nodes::Document
|
125
|
+
# Psych.parse("---\n - a\n - b")
|
126
|
+
#
|
127
|
+
# ==== Reading from a file
|
128
|
+
#
|
129
|
+
# # Returns Psych::Nodes::Stream
|
130
|
+
# Psych.parse_stream(File.read('database.yml'))
|
131
|
+
#
|
132
|
+
# # Returns Psych::Nodes::Document
|
133
|
+
# Psych.parse_file('database.yml')
|
134
|
+
#
|
135
|
+
# ==== Exception handling
|
136
|
+
#
|
137
|
+
# begin
|
138
|
+
# # The second argument chnages only the exception contents
|
139
|
+
# Psych.parse("--- `", "file.txt")
|
140
|
+
# rescue Psych::SyntaxError => ex
|
141
|
+
# ex.file # => 'file.txt'
|
142
|
+
# ex.message # => "(file.txt): found character that cannot start any token"
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
# === Emitting
|
146
|
+
#
|
147
|
+
# At the mid level is building an AST. This AST is exactly the same as the AST
|
148
|
+
# used when parsing a YAML document. Users can build an AST by hand and the
|
149
|
+
# AST knows how to emit itself as a YAML document. See Psych::Nodes,
|
150
|
+
# Psych::Nodes::Node, and Psych::TreeBuilder for more information on building
|
151
|
+
# a YAML AST.
|
152
|
+
#
|
153
|
+
# ==== Writing to a string
|
154
|
+
#
|
155
|
+
# # We need Psych::Nodes::Stream (not Psych::Nodes::Document)
|
156
|
+
# stream = Psych.parse_stream("---\n - a\n - b")
|
157
|
+
#
|
158
|
+
# stream.to_yaml # => "---\n- a\n- b\n"
|
159
|
+
#
|
160
|
+
# ==== Writing to a file
|
161
|
+
#
|
162
|
+
# # We need Psych::Nodes::Stream (not Psych::Nodes::Document)
|
163
|
+
# stream = Psych.parse_stream(File.read('database.yml'))
|
164
|
+
#
|
165
|
+
# File.open('database.yml', 'w') do |file|
|
166
|
+
# file.write(stream.to_yaml)
|
167
|
+
# end
|
168
|
+
#
|
169
|
+
# == Low-level API
|
170
|
+
#
|
171
|
+
# === Parsing
|
172
|
+
#
|
173
|
+
# The lowest level parser should be used when the YAML input is already known,
|
174
|
+
# and the developer does not want to pay the price of building an AST or
|
175
|
+
# automatic detection and conversion to ruby objects. See Psych::Parser for
|
176
|
+
# more information on using the event based parser.
|
177
|
+
#
|
178
|
+
# ==== Reading to Psych::Nodes::Stream structure
|
179
|
+
#
|
180
|
+
# parser = Psych::Parser.new(TreeBuilder.new) # => #<Psych::Parser>
|
181
|
+
# parser = Psych.parser # it's an alias for the above
|
182
|
+
#
|
183
|
+
# parser.parse("---\n - a\n - b") # => #<Psych::Parser>
|
184
|
+
# parser.handler # => #<Psych::TreeBuilder>
|
185
|
+
# parser.handler.root # => #<Psych::Nodes::Stream>
|
186
|
+
#
|
187
|
+
# ==== Receiving an events stream
|
188
|
+
#
|
189
|
+
# parser = Psych::Parser.new(Psych::Handlers::Recorder.new)
|
190
|
+
#
|
191
|
+
# parser.parse("---\n - a\n - b")
|
192
|
+
# parser.events # => [list of [event, args] lists]
|
193
|
+
# # event is one of: Psych::Handler::EVENTS
|
194
|
+
# # args are the arguments passed to the event
|
195
|
+
#
|
196
|
+
# === Emitting
|
197
|
+
#
|
198
|
+
# The lowest level emitter is an event based system. Events are sent to a
|
199
|
+
# Psych::Emitter object. That object knows how to convert the events to a YAML
|
200
|
+
# document. This interface should be used when document format is known in
|
201
|
+
# advance or speed is a concern. See Psych::Emitter for more information.
|
202
|
+
#
|
203
|
+
# ==== Writing to a ruby structure
|
204
|
+
#
|
205
|
+
# Psych.parser.parse("--- a") # => #<Psych::Parser>
|
206
|
+
#
|
207
|
+
# parser.handler.first # => #<Psych::Nodes::Stream>
|
208
|
+
# parser.handler.first.to_ruby # => ["a"]
|
209
|
+
#
|
210
|
+
# parser.handler.root.first # => #<Psych::Nodes::Document>
|
211
|
+
# parser.handler.root.first.to_ruby # => "a"
|
212
|
+
#
|
213
|
+
# # You can instantiate an Emitter manually
|
214
|
+
# Psych::Visitors::ToRuby.new.accept(parser.handler.root.first)
|
215
|
+
# # => "a"
|
216
|
+
|
217
|
+
module Psych
|
218
|
+
# The version is Psych you're using
|
219
|
+
VERSION = '2.0.0'
|
220
|
+
|
221
|
+
# The version of libyaml Psych is using
|
222
|
+
LIBYAML_VERSION = Psych.libyaml_version.join '.'
|
223
|
+
|
224
|
+
###
|
225
|
+
# Load +yaml+ in to a Ruby data structure. If multiple documents are
|
226
|
+
# provided, the object contained in the first document will be returned.
|
227
|
+
# +filename+ will be used in the exception message if any exception is raised
|
228
|
+
# while parsing.
|
229
|
+
#
|
230
|
+
# Raises a Psych::SyntaxError when a YAML syntax error is detected.
|
231
|
+
#
|
232
|
+
# Example:
|
233
|
+
#
|
234
|
+
# Psych.load("--- a") # => 'a'
|
235
|
+
# Psych.load("---\n - a\n - b") # => ['a', 'b']
|
236
|
+
#
|
237
|
+
# begin
|
238
|
+
# Psych.load("--- `", "file.txt")
|
239
|
+
# rescue Psych::SyntaxError => ex
|
240
|
+
# ex.file # => 'file.txt'
|
241
|
+
# ex.message # => "(file.txt): found character that cannot start any token"
|
242
|
+
# end
|
243
|
+
def self.load yaml, filename = nil
|
244
|
+
result = parse(yaml, filename)
|
245
|
+
result ? result.to_ruby : result
|
246
|
+
end
|
247
|
+
|
248
|
+
###
|
249
|
+
# Safely load the yaml string in +yaml+. By default, only the following
|
250
|
+
# classes are allowed to be deserialized:
|
251
|
+
#
|
252
|
+
# * TrueClass
|
253
|
+
# * FalseClass
|
254
|
+
# * NilClass
|
255
|
+
# * Numeric
|
256
|
+
# * String
|
257
|
+
# * Array
|
258
|
+
# * Hash
|
259
|
+
#
|
260
|
+
# Recursive data structures are not allowed by default. Arbitrary classes
|
261
|
+
# can be allowed by adding those classes to the +whitelist+. They are
|
262
|
+
# additive. For example, to allow Date deserialization:
|
263
|
+
#
|
264
|
+
# Psych.safe_load(yaml, [Date])
|
265
|
+
#
|
266
|
+
# Now the Date class can be loaded in addition to the classes listed above.
|
267
|
+
#
|
268
|
+
# Aliases can be explicitly allowed by changing the +aliases+ parameter.
|
269
|
+
# For example:
|
270
|
+
#
|
271
|
+
# x = []
|
272
|
+
# x << x
|
273
|
+
# yaml = Psych.dump x
|
274
|
+
# Psych.safe_load yaml # => raises an exception
|
275
|
+
# Psych.safe_load yaml, [], [], true # => loads the aliases
|
276
|
+
#
|
277
|
+
# A Psych::DisallowedClass exception will be raised if the yaml contains a
|
278
|
+
# class that isn't in the whitelist.
|
279
|
+
#
|
280
|
+
# A Psych::BadAlias exception will be raised if the yaml contains aliases
|
281
|
+
# but the +aliases+ parameter is set to false.
|
282
|
+
def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil
|
283
|
+
result = parse(yaml, filename)
|
284
|
+
return unless result
|
285
|
+
|
286
|
+
class_loader = ClassLoader::Restricted.new(whitelist_classes.map(&:to_s),
|
287
|
+
whitelist_symbols.map(&:to_s))
|
288
|
+
scanner = ScalarScanner.new class_loader
|
289
|
+
if aliases
|
290
|
+
visitor = Visitors::ToRuby.new scanner, class_loader
|
291
|
+
else
|
292
|
+
visitor = Visitors::NoAliasRuby.new scanner, class_loader
|
293
|
+
end
|
294
|
+
visitor.accept result
|
295
|
+
end
|
296
|
+
|
297
|
+
###
|
298
|
+
# Parse a YAML string in +yaml+. Returns the Psych::Nodes::Document.
|
299
|
+
# +filename+ is used in the exception message if a Psych::SyntaxError is
|
300
|
+
# raised.
|
301
|
+
#
|
302
|
+
# Raises a Psych::SyntaxError when a YAML syntax error is detected.
|
303
|
+
#
|
304
|
+
# Example:
|
305
|
+
#
|
306
|
+
# Psych.parse("---\n - a\n - b") # => #<Psych::Nodes::Document:0x00>
|
307
|
+
#
|
308
|
+
# begin
|
309
|
+
# Psych.parse("--- `", "file.txt")
|
310
|
+
# rescue Psych::SyntaxError => ex
|
311
|
+
# ex.file # => 'file.txt'
|
312
|
+
# ex.message # => "(file.txt): found character that cannot start any token"
|
313
|
+
# end
|
314
|
+
#
|
315
|
+
# See Psych::Nodes for more information about YAML AST.
|
316
|
+
def self.parse yaml, filename = nil
|
317
|
+
parse_stream(yaml, filename) do |node|
|
318
|
+
return node
|
319
|
+
end
|
320
|
+
false
|
321
|
+
end
|
322
|
+
|
323
|
+
###
|
324
|
+
# Parse a file at +filename+. Returns the Psych::Nodes::Document.
|
325
|
+
#
|
326
|
+
# Raises a Psych::SyntaxError when a YAML syntax error is detected.
|
327
|
+
def self.parse_file filename
|
328
|
+
File.open filename, 'r:bom|utf-8' do |f|
|
329
|
+
parse f, filename
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
###
|
334
|
+
# Returns a default parser
|
335
|
+
def self.parser
|
336
|
+
Psych::Parser.new(TreeBuilder.new)
|
337
|
+
end
|
338
|
+
|
339
|
+
###
|
340
|
+
# Parse a YAML string in +yaml+. Returns the Psych::Nodes::Stream.
|
341
|
+
# This method can handle multiple YAML documents contained in +yaml+.
|
342
|
+
# +filename+ is used in the exception message if a Psych::SyntaxError is
|
343
|
+
# raised.
|
344
|
+
#
|
345
|
+
# If a block is given, a Psych::Nodes::Document node will be yielded to the
|
346
|
+
# block as it's being parsed.
|
347
|
+
#
|
348
|
+
# Raises a Psych::SyntaxError when a YAML syntax error is detected.
|
349
|
+
#
|
350
|
+
# Example:
|
351
|
+
#
|
352
|
+
# Psych.parse_stream("---\n - a\n - b") # => #<Psych::Nodes::Stream:0x00>
|
353
|
+
#
|
354
|
+
# Psych.parse_stream("--- a\n--- b") do |node|
|
355
|
+
# node # => #<Psych::Nodes::Document:0x00>
|
356
|
+
# end
|
357
|
+
#
|
358
|
+
# begin
|
359
|
+
# Psych.parse_stream("--- `", "file.txt")
|
360
|
+
# rescue Psych::SyntaxError => ex
|
361
|
+
# ex.file # => 'file.txt'
|
362
|
+
# ex.message # => "(file.txt): found character that cannot start any token"
|
363
|
+
# end
|
364
|
+
#
|
365
|
+
# See Psych::Nodes for more information about YAML AST.
|
366
|
+
def self.parse_stream yaml, filename = nil, &block
|
367
|
+
if block_given?
|
368
|
+
parser = Psych::Parser.new(Handlers::DocumentStream.new(&block))
|
369
|
+
parser.parse yaml, filename
|
370
|
+
else
|
371
|
+
parser = self.parser
|
372
|
+
parser.parse yaml, filename
|
373
|
+
parser.handler.root
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
###
|
378
|
+
# call-seq:
|
379
|
+
# Psych.dump(o) -> string of yaml
|
380
|
+
# Psych.dump(o, options) -> string of yaml
|
381
|
+
# Psych.dump(o, io) -> io object passed in
|
382
|
+
# Psych.dump(o, io, options) -> io object passed in
|
383
|
+
#
|
384
|
+
# Dump Ruby object +o+ to a YAML string. Optional +options+ may be passed in
|
385
|
+
# to control the output format. If an IO object is passed in, the YAML will
|
386
|
+
# be dumped to that IO object.
|
387
|
+
#
|
388
|
+
# Example:
|
389
|
+
#
|
390
|
+
# # Dump an array, get back a YAML string
|
391
|
+
# Psych.dump(['a', 'b']) # => "---\n- a\n- b\n"
|
392
|
+
#
|
393
|
+
# # Dump an array to an IO object
|
394
|
+
# Psych.dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890>
|
395
|
+
#
|
396
|
+
# # Dump an array with indentation set
|
397
|
+
# Psych.dump(['a', ['b']], :indentation => 3) # => "---\n- a\n- - b\n"
|
398
|
+
#
|
399
|
+
# # Dump an array to an IO with indentation set
|
400
|
+
# Psych.dump(['a', ['b']], StringIO.new, :indentation => 3)
|
401
|
+
def self.dump o, io = nil, options = {}
|
402
|
+
if Hash === io
|
403
|
+
options = io
|
404
|
+
io = nil
|
405
|
+
end
|
406
|
+
|
407
|
+
visitor = Psych::Visitors::YAMLTree.create options
|
408
|
+
visitor << o
|
409
|
+
visitor.tree.yaml io, options
|
410
|
+
end
|
411
|
+
|
412
|
+
###
|
413
|
+
# Dump a list of objects as separate documents to a document stream.
|
414
|
+
#
|
415
|
+
# Example:
|
416
|
+
#
|
417
|
+
# Psych.dump_stream("foo\n ", {}) # => "--- ! \"foo\\n \"\n--- {}\n"
|
418
|
+
def self.dump_stream *objects
|
419
|
+
visitor = Psych::Visitors::YAMLTree.create({})
|
420
|
+
objects.each do |o|
|
421
|
+
visitor << o
|
422
|
+
end
|
423
|
+
visitor.tree.yaml
|
424
|
+
end
|
425
|
+
|
426
|
+
###
|
427
|
+
# Dump Ruby +object+ to a JSON string.
|
428
|
+
def self.to_json object
|
429
|
+
visitor = Psych::Visitors::JSONTree.create
|
430
|
+
visitor << object
|
431
|
+
visitor.tree.yaml
|
432
|
+
end
|
433
|
+
|
434
|
+
###
|
435
|
+
# Load multiple documents given in +yaml+. Returns the parsed documents
|
436
|
+
# as a list. If a block is given, each document will be converted to ruby
|
437
|
+
# and passed to the block during parsing
|
438
|
+
#
|
439
|
+
# Example:
|
440
|
+
#
|
441
|
+
# Psych.load_stream("--- foo\n...\n--- bar\n...") # => ['foo', 'bar']
|
442
|
+
#
|
443
|
+
# list = []
|
444
|
+
# Psych.load_stream("--- foo\n...\n--- bar\n...") do |ruby|
|
445
|
+
# list << ruby
|
446
|
+
# end
|
447
|
+
# list # => ['foo', 'bar']
|
448
|
+
#
|
449
|
+
def self.load_stream yaml, filename = nil
|
450
|
+
if block_given?
|
451
|
+
parse_stream(yaml, filename) do |node|
|
452
|
+
yield node.to_ruby
|
453
|
+
end
|
454
|
+
else
|
455
|
+
parse_stream(yaml, filename).children.map { |child| child.to_ruby }
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
###
|
460
|
+
# Load the document contained in +filename+. Returns the yaml contained in
|
461
|
+
# +filename+ as a ruby object
|
462
|
+
def self.load_file filename
|
463
|
+
File.open(filename, 'r:bom|utf-8') { |f| self.load f, filename }
|
464
|
+
end
|
465
|
+
|
466
|
+
# :stopdoc:
|
467
|
+
@domain_types = {}
|
468
|
+
def self.add_domain_type domain, type_tag, &block
|
469
|
+
key = ['tag', domain, type_tag].join ':'
|
470
|
+
@domain_types[key] = [key, block]
|
471
|
+
@domain_types["tag:#{type_tag}"] = [key, block]
|
472
|
+
end
|
473
|
+
|
474
|
+
def self.add_builtin_type type_tag, &block
|
475
|
+
domain = 'yaml.org,2002'
|
476
|
+
key = ['tag', domain, type_tag].join ':'
|
477
|
+
@domain_types[key] = [key, block]
|
478
|
+
end
|
479
|
+
|
480
|
+
def self.remove_type type_tag
|
481
|
+
@domain_types.delete type_tag
|
482
|
+
end
|
483
|
+
|
484
|
+
@load_tags = {}
|
485
|
+
@dump_tags = {}
|
486
|
+
def self.add_tag tag, klass
|
487
|
+
@load_tags[tag] = klass.name
|
488
|
+
@dump_tags[klass] = tag
|
489
|
+
end
|
490
|
+
|
491
|
+
class << self
|
492
|
+
attr_accessor :load_tags
|
493
|
+
attr_accessor :dump_tags
|
494
|
+
attr_accessor :domain_types
|
495
|
+
end
|
496
|
+
# :startdoc:
|
497
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
# V=0 quiet, V=1 verbose. other values don't work.
|
5
|
+
V = 0
|
6
|
+
Q1 = $(V:1=)
|
7
|
+
Q = $(Q1:0=@)
|
8
|
+
n=$(NULLCMD)
|
9
|
+
ECHO1 = $(V:1=@$n)
|
10
|
+
ECHO = $(ECHO1:0=@echo)
|
11
|
+
|
12
|
+
#### Start of system configuration section. ####
|
13
|
+
|
14
|
+
srcdir = ../../../../ext/psych
|
15
|
+
topdir = /Users/dylanlacey/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1
|
16
|
+
hdrdir = /Users/dylanlacey/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1
|
17
|
+
arch_hdrdir = /Users/dylanlacey/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1/$(arch)
|
18
|
+
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
19
|
+
prefix = $(DESTDIR)/Users/dylanlacey/.rvm/rubies/ruby-1.9.3-p392
|
20
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
21
|
+
exec_prefix = $(prefix)
|
22
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
23
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
24
|
+
rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
25
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
26
|
+
sitedir = $(rubylibprefix)/site_ruby
|
27
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
28
|
+
mandir = $(datarootdir)/man
|
29
|
+
localedir = $(datarootdir)/locale
|
30
|
+
libdir = $(exec_prefix)/lib
|
31
|
+
psdir = $(docdir)
|
32
|
+
pdfdir = $(docdir)
|
33
|
+
dvidir = $(docdir)
|
34
|
+
htmldir = $(docdir)
|
35
|
+
infodir = $(datarootdir)/info
|
36
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
37
|
+
oldincludedir = $(DESTDIR)/usr/include
|
38
|
+
includedir = $(prefix)/include
|
39
|
+
localstatedir = $(prefix)/var
|
40
|
+
sharedstatedir = $(prefix)/com
|
41
|
+
sysconfdir = $(prefix)/etc
|
42
|
+
datadir = $(datarootdir)
|
43
|
+
datarootdir = $(prefix)/share
|
44
|
+
libexecdir = $(exec_prefix)/libexec
|
45
|
+
sbindir = $(exec_prefix)/sbin
|
46
|
+
bindir = $(exec_prefix)/bin
|
47
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
48
|
+
archdir = $(rubylibdir)/$(arch)
|
49
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
50
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
51
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
52
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
53
|
+
|
54
|
+
NULLCMD = :
|
55
|
+
|
56
|
+
CC = /opt/local/bin/gcc-apple-4.2
|
57
|
+
CXX = g++
|
58
|
+
LIBRUBY = $(LIBRUBY_SO)
|
59
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
60
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
61
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
62
|
+
empty =
|
63
|
+
OUTFLAG = -o $(empty)
|
64
|
+
COUTFLAG = -o $(empty)
|
65
|
+
|
66
|
+
RUBY_EXTCONF_H =
|
67
|
+
cflags = $(optflags) $(debugflags) $(warnflags)
|
68
|
+
optflags = -O3
|
69
|
+
debugflags = -ggdb
|
70
|
+
warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration
|
71
|
+
CFLAGS = -fno-common $(cflags) -fno-common -pipe $(ARCH_FLAG)
|
72
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
73
|
+
DEFS =
|
74
|
+
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags) -I/opt/local/include
|
75
|
+
CXXFLAGS = $(CFLAGS) $(cxxflags)
|
76
|
+
ldflags = -L. -L/usr/local/lib -L/opt/local/lib
|
77
|
+
dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace -L/opt/local/lib
|
78
|
+
ARCH_FLAG =
|
79
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
80
|
+
LDSHARED = $(CC) -dynamic -bundle
|
81
|
+
LDSHAREDXX = $(CXX) -dynamic -bundle
|
82
|
+
AR = ar
|
83
|
+
EXEEXT =
|
84
|
+
|
85
|
+
RUBY_BASE_NAME = ruby
|
86
|
+
RUBY_INSTALL_NAME = ruby
|
87
|
+
RUBY_SO_NAME = ruby.1.9.1
|
88
|
+
arch = x86_64-darwin12.3.0
|
89
|
+
sitearch = $(arch)
|
90
|
+
ruby_version = 1.9.1
|
91
|
+
ruby = /Users/dylanlacey/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
|
92
|
+
RUBY = $(ruby)
|
93
|
+
RM = rm -f
|
94
|
+
RM_RF = $(RUBY) -run -e rm -- -rf
|
95
|
+
RMDIRS = rmdir -p
|
96
|
+
MAKEDIRS = mkdir -p
|
97
|
+
INSTALL = /usr/bin/install -c
|
98
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
99
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
100
|
+
COPY = cp
|
101
|
+
TOUCH = exit >
|
102
|
+
|
103
|
+
#### End of system configuration section. ####
|
104
|
+
|
105
|
+
preload =
|
106
|
+
|
107
|
+
libpath = . $(libdir) /opt/local/lib
|
108
|
+
LIBPATH = -L. -L$(libdir) -L/opt/local/lib
|
109
|
+
DEFFILE =
|
110
|
+
|
111
|
+
CLEANFILES = mkmf.log
|
112
|
+
DISTCLEANFILES =
|
113
|
+
DISTCLEANDIRS =
|
114
|
+
|
115
|
+
extout =
|
116
|
+
extout_prefix =
|
117
|
+
target_prefix =
|
118
|
+
LOCAL_LIBS =
|
119
|
+
LIBS = $(LIBRUBYARG_SHARED) -lyaml -lpthread -ldl -lobjc
|
120
|
+
SRCS = psych.c psych_emitter.c psych_parser.c psych_to_ruby.c psych_yaml_tree.c
|
121
|
+
OBJS = psych.o psych_emitter.o psych_parser.o psych_to_ruby.o psych_yaml_tree.o
|
122
|
+
TARGET = psych
|
123
|
+
DLLIB = $(TARGET).bundle
|
124
|
+
EXTSTATIC =
|
125
|
+
STATIC_LIB =
|
126
|
+
|
127
|
+
BINDIR = $(bindir)
|
128
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
129
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
130
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
131
|
+
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
132
|
+
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
133
|
+
|
134
|
+
TARGET_SO = $(DLLIB)
|
135
|
+
CLEANLIBS = $(TARGET).bundle
|
136
|
+
CLEANOBJS = *.o *.bak
|
137
|
+
|
138
|
+
all: $(DLLIB)
|
139
|
+
static: $(STATIC_LIB)
|
140
|
+
.PHONY: all install static install-so install-rb
|
141
|
+
.PHONY: clean clean-so clean-rb
|
142
|
+
|
143
|
+
clean-static::
|
144
|
+
clean-rb-default::
|
145
|
+
clean-rb::
|
146
|
+
clean-so::
|
147
|
+
clean: clean-so clean-static clean-rb-default clean-rb
|
148
|
+
-$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
|
149
|
+
|
150
|
+
distclean-rb-default::
|
151
|
+
distclean-rb::
|
152
|
+
distclean-so::
|
153
|
+
distclean: clean distclean-so distclean-rb-default distclean-rb
|
154
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
155
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
156
|
+
@-$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
|
157
|
+
|
158
|
+
realclean: distclean
|
159
|
+
install: install-so install-rb
|
160
|
+
|
161
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
162
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
163
|
+
-$(Q)$(MAKEDIRS) $(@D)
|
164
|
+
$(INSTALL_PROG) $(DLLIB) $(@D)
|
165
|
+
clean-static::
|
166
|
+
-$(Q)$(RM) $(STATIC_LIB)
|
167
|
+
install-rb: pre-install-rb install-rb-default
|
168
|
+
install-rb-default: pre-install-rb-default
|
169
|
+
pre-install-rb: Makefile
|
170
|
+
pre-install-rb-default: Makefile
|
171
|
+
pre-install-rb-default:
|
172
|
+
$(ECHO) installing default psych libraries
|
173
|
+
./.RUBYARCHDIR.time:
|
174
|
+
$(Q) $(MAKEDIRS) $(RUBYARCHDIR)
|
175
|
+
$(Q) $(TOUCH) $@
|
176
|
+
|
177
|
+
site-install: site-install-so site-install-rb
|
178
|
+
site-install-so: install-so
|
179
|
+
site-install-rb: install-rb
|
180
|
+
|
181
|
+
.SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
|
182
|
+
|
183
|
+
.cc.o:
|
184
|
+
$(ECHO) compiling $(<)
|
185
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
186
|
+
|
187
|
+
.mm.o:
|
188
|
+
$(ECHO) compiling $(<)
|
189
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
190
|
+
|
191
|
+
.cxx.o:
|
192
|
+
$(ECHO) compiling $(<)
|
193
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
194
|
+
|
195
|
+
.cpp.o:
|
196
|
+
$(ECHO) compiling $(<)
|
197
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
198
|
+
|
199
|
+
.C.o:
|
200
|
+
$(ECHO) compiling $(<)
|
201
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
202
|
+
|
203
|
+
.c.o:
|
204
|
+
$(ECHO) compiling $(<)
|
205
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
206
|
+
|
207
|
+
.m.o:
|
208
|
+
$(ECHO) compiling $(<)
|
209
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
210
|
+
|
211
|
+
$(DLLIB): $(OBJS) Makefile
|
212
|
+
$(ECHO) linking shared-object $(DLLIB)
|
213
|
+
-$(Q)$(RM) $(@)
|
214
|
+
$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
###
|
219
|
+
$(OBJS): $(HDRS) $(ruby_headers) \
|
220
|
+
$(hdrdir)/ruby/encoding.h \
|
221
|
+
$(hdrdir)/ruby/oniguruma.h
|