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,29 @@
1
+ module Psych
2
+ module JSON
3
+ module YAMLEvents # :nodoc:
4
+ def start_document version, tag_directives, implicit
5
+ super(version, tag_directives, !streaming?)
6
+ end
7
+
8
+ def end_document implicit_end = !streaming?
9
+ super(implicit_end)
10
+ end
11
+
12
+ def start_mapping anchor, tag, implicit, style
13
+ super(anchor, nil, true, Nodes::Mapping::FLOW)
14
+ end
15
+
16
+ def start_sequence anchor, tag, implicit, style
17
+ super(anchor, nil, true, Nodes::Sequence::FLOW)
18
+ end
19
+
20
+ def scalar value, anchor, tag, plain, quoted, style
21
+ if "tag:yaml.org,2002:null" == tag
22
+ super('null', nil, nil, true, false, Nodes::Scalar::PLAIN)
23
+ else
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ module Psych
2
+ module Nodes
3
+ ###
4
+ # This class represents a {YAML Alias}[http://yaml.org/spec/1.1/#alias].
5
+ # It points to an +anchor+.
6
+ #
7
+ # A Psych::Nodes::Alias is a terminal node and may have no children.
8
+ class Alias < Psych::Nodes::Node
9
+ # The anchor this alias links to
10
+ attr_accessor :anchor
11
+
12
+ # Create a new Alias that points to an +anchor+
13
+ def initialize anchor
14
+ @anchor = anchor
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,60 @@
1
+ module Psych
2
+ module Nodes
3
+ ###
4
+ # This represents a YAML Document. This node must be a child of
5
+ # Psych::Nodes::Stream. A Psych::Nodes::Document must have one child,
6
+ # and that child may be one of the following:
7
+ #
8
+ # * Psych::Nodes::Sequence
9
+ # * Psych::Nodes::Mapping
10
+ # * Psych::Nodes::Scalar
11
+ class Document < Psych::Nodes::Node
12
+ # The version of the YAML document
13
+ attr_accessor :version
14
+
15
+ # A list of tag directives for this document
16
+ attr_accessor :tag_directives
17
+
18
+ # Was this document implicitly created?
19
+ attr_accessor :implicit
20
+
21
+ # Is the end of the document implicit?
22
+ attr_accessor :implicit_end
23
+
24
+ ###
25
+ # Create a new Psych::Nodes::Document object.
26
+ #
27
+ # +version+ is a list indicating the YAML version.
28
+ # +tags_directives+ is a list of tag directive declarations
29
+ # +implicit+ is a flag indicating whether the document will be implicitly
30
+ # started.
31
+ #
32
+ # == Example:
33
+ # This creates a YAML document object that represents a YAML 1.1 document
34
+ # with one tag directive, and has an implicit start:
35
+ #
36
+ # Psych::Nodes::Document.new(
37
+ # [1,1],
38
+ # [["!", "tag:tenderlovemaking.com,2009:"]],
39
+ # true
40
+ # )
41
+ #
42
+ # == See Also
43
+ # See also Psych::Handler#start_document
44
+ def initialize version = [], tag_directives = [], implicit = false
45
+ super()
46
+ @version = version
47
+ @tag_directives = tag_directives
48
+ @implicit = implicit
49
+ @implicit_end = true
50
+ end
51
+
52
+ ###
53
+ # Returns the root node. A Document may only have one root node:
54
+ # http://yaml.org/spec/1.1/#id898031
55
+ def root
56
+ children.first
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,56 @@
1
+ module Psych
2
+ module Nodes
3
+ ###
4
+ # This class represents a {YAML Mapping}[http://yaml.org/spec/1.1/#mapping].
5
+ #
6
+ # A Psych::Nodes::Mapping node may have 0 or more children, but must have
7
+ # an even number of children. Here are the valid children a
8
+ # Psych::Nodes::Mapping node may have:
9
+ #
10
+ # * Psych::Nodes::Sequence
11
+ # * Psych::Nodes::Mapping
12
+ # * Psych::Nodes::Scalar
13
+ # * Psych::Nodes::Alias
14
+ class Mapping < Psych::Nodes::Node
15
+ # Any Map Style
16
+ ANY = 0
17
+
18
+ # Block Map Style
19
+ BLOCK = 1
20
+
21
+ # Flow Map Style
22
+ FLOW = 2
23
+
24
+ # The optional anchor for this mapping
25
+ attr_accessor :anchor
26
+
27
+ # The optional tag for this mapping
28
+ attr_accessor :tag
29
+
30
+ # Is this an implicit mapping?
31
+ attr_accessor :implicit
32
+
33
+ # The style of this mapping
34
+ attr_accessor :style
35
+
36
+ ###
37
+ # Create a new Psych::Nodes::Mapping object.
38
+ #
39
+ # +anchor+ is the anchor associated with the map or +nil+.
40
+ # +tag+ is the tag associated with the map or +nil+.
41
+ # +implicit+ is a boolean indicating whether or not the map was implicitly
42
+ # started.
43
+ # +style+ is an integer indicating the mapping style.
44
+ #
45
+ # == See Also
46
+ # See also Psych::Handler#start_mapping
47
+ def initialize anchor = nil, tag = nil, implicit = true, style = BLOCK
48
+ super()
49
+ @anchor = anchor
50
+ @tag = tag
51
+ @implicit = implicit
52
+ @style = style
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,55 @@
1
+ require 'stringio'
2
+ require 'psych/class_loader'
3
+ require 'psych/scalar_scanner'
4
+
5
+ module Psych
6
+ module Nodes
7
+ ###
8
+ # The base class for any Node in a YAML parse tree. This class should
9
+ # never be instantiated.
10
+ class Node
11
+ include Enumerable
12
+
13
+ # The children of this node
14
+ attr_reader :children
15
+
16
+ # An associated tag
17
+ attr_reader :tag
18
+
19
+ # Create a new Psych::Nodes::Node
20
+ def initialize
21
+ @children = []
22
+ end
23
+
24
+ ###
25
+ # Iterate over each node in the tree. Yields each node to +block+ depth
26
+ # first.
27
+ def each &block
28
+ return enum_for :each unless block_given?
29
+ Visitors::DepthFirst.new(block).accept self
30
+ end
31
+
32
+ ###
33
+ # Convert this node to Ruby.
34
+ #
35
+ # See also Psych::Visitors::ToRuby
36
+ def to_ruby
37
+ Visitors::ToRuby.create.accept(self)
38
+ end
39
+ alias :transform :to_ruby
40
+
41
+ ###
42
+ # Convert this node to YAML.
43
+ #
44
+ # See also Psych::Visitors::Emitter
45
+ def yaml io = nil, options = {}
46
+ real_io = io || StringIO.new(''.encode('utf-8'))
47
+
48
+ Visitors::Emitter.new(real_io, options).accept self
49
+ return real_io.string unless io
50
+ io
51
+ end
52
+ alias :to_yaml :yaml
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,67 @@
1
+ module Psych
2
+ module Nodes
3
+ ###
4
+ # This class represents a {YAML Scalar}[http://yaml.org/spec/1.1/#id858081].
5
+ #
6
+ # This node type is a terminal node and should not have any children.
7
+ class Scalar < Psych::Nodes::Node
8
+ # Any style scalar, the emitter chooses
9
+ ANY = 0
10
+
11
+ # Plain scalar style
12
+ PLAIN = 1
13
+
14
+ # Single quoted style
15
+ SINGLE_QUOTED = 2
16
+
17
+ # Double quoted style
18
+ DOUBLE_QUOTED = 3
19
+
20
+ # Literal style
21
+ LITERAL = 4
22
+
23
+ # Folded style
24
+ FOLDED = 5
25
+
26
+ # The scalar value
27
+ attr_accessor :value
28
+
29
+ # The anchor value (if there is one)
30
+ attr_accessor :anchor
31
+
32
+ # The tag value (if there is one)
33
+ attr_accessor :tag
34
+
35
+ # Is this a plain scalar?
36
+ attr_accessor :plain
37
+
38
+ # Is this scalar quoted?
39
+ attr_accessor :quoted
40
+
41
+ # The style of this scalar
42
+ attr_accessor :style
43
+
44
+ ###
45
+ # Create a new Psych::Nodes::Scalar object.
46
+ #
47
+ # +value+ is the string value of the scalar
48
+ # +anchor+ is an associated anchor or nil
49
+ # +tag+ is an associated tag or nil
50
+ # +plain+ is a boolean value
51
+ # +quoted+ is a boolean value
52
+ # +style+ is an integer idicating the string style
53
+ #
54
+ # == See Also
55
+ #
56
+ # See also Psych::Handler#scalar
57
+ def initialize value, anchor = nil, tag = nil, plain = true, quoted = false, style = ANY
58
+ @value = value
59
+ @anchor = anchor
60
+ @tag = tag
61
+ @plain = plain
62
+ @quoted = quoted
63
+ @style = style
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,81 @@
1
+ module Psych
2
+ module Nodes
3
+ ###
4
+ # This class represents a
5
+ # {YAML sequence}[http://yaml.org/spec/1.1/#sequence/syntax].
6
+ #
7
+ # A YAML sequence is basically a list, and looks like this:
8
+ #
9
+ # %YAML 1.1
10
+ # ---
11
+ # - I am
12
+ # - a Sequence
13
+ #
14
+ # A YAML sequence may have an anchor like this:
15
+ #
16
+ # %YAML 1.1
17
+ # ---
18
+ # &A [
19
+ # "This sequence",
20
+ # "has an anchor"
21
+ # ]
22
+ #
23
+ # A YAML sequence may also have a tag like this:
24
+ #
25
+ # %YAML 1.1
26
+ # ---
27
+ # !!seq [
28
+ # "This sequence",
29
+ # "has a tag"
30
+ # ]
31
+ #
32
+ # This class represents a sequence in a YAML document. A
33
+ # Psych::Nodes::Sequence node may have 0 or more children. Valid children
34
+ # for this node are:
35
+ #
36
+ # * Psych::Nodes::Sequence
37
+ # * Psych::Nodes::Mapping
38
+ # * Psych::Nodes::Scalar
39
+ # * Psych::Nodes::Alias
40
+ class Sequence < Psych::Nodes::Node
41
+ # Any Styles, emitter chooses
42
+ ANY = 0
43
+
44
+ # Block style sequence
45
+ BLOCK = 1
46
+
47
+ # Flow style sequence
48
+ FLOW = 2
49
+
50
+ # The anchor for this sequence (if any)
51
+ attr_accessor :anchor
52
+
53
+ # The tag name for this sequence (if any)
54
+ attr_accessor :tag
55
+
56
+ # Is this sequence started implicitly?
57
+ attr_accessor :implicit
58
+
59
+ # The sequece style used
60
+ attr_accessor :style
61
+
62
+ ###
63
+ # Create a new object representing a YAML sequence.
64
+ #
65
+ # +anchor+ is the anchor associated with the sequence or nil.
66
+ # +tag+ is the tag associated with the sequence or nil.
67
+ # +implicit+ a boolean indicating whether or not the sequence was
68
+ # implicitly started.
69
+ # +style+ is an integer indicating the list style.
70
+ #
71
+ # See Psych::Handler#start_sequence
72
+ def initialize anchor = nil, tag = nil, implicit = true, style = BLOCK
73
+ super()
74
+ @anchor = anchor
75
+ @tag = tag
76
+ @implicit = implicit
77
+ @style = style
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,37 @@
1
+ module Psych
2
+ module Nodes
3
+ ###
4
+ # Represents a YAML stream. This is the root node for any YAML parse
5
+ # tree. This node must have one or more child nodes. The only valid
6
+ # child node for a Psych::Nodes::Stream node is Psych::Nodes::Document.
7
+ class Stream < Psych::Nodes::Node
8
+
9
+ # Encodings supported by Psych (and libyaml)
10
+
11
+ # Any encoding
12
+ ANY = Psych::Parser::ANY
13
+
14
+ # UTF-8 encoding
15
+ UTF8 = Psych::Parser::UTF8
16
+
17
+ # UTF-16LE encoding
18
+ UTF16LE = Psych::Parser::UTF16LE
19
+
20
+ # UTF-16BE encoding
21
+ UTF16BE = Psych::Parser::UTF16BE
22
+
23
+ # The encoding used for this stream
24
+ attr_accessor :encoding
25
+
26
+ ###
27
+ # Create a new Psych::Nodes::Stream node with an +encoding+ that
28
+ # defaults to Psych::Nodes::Stream::UTF8.
29
+ #
30
+ # See also Psych::Handler#start_stream
31
+ def initialize encoding = UTF8
32
+ super()
33
+ @encoding = encoding
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,77 @@
1
+ require 'psych/nodes/node'
2
+ require 'psych/nodes/stream'
3
+ require 'psych/nodes/document'
4
+ require 'psych/nodes/sequence'
5
+ require 'psych/nodes/scalar'
6
+ require 'psych/nodes/mapping'
7
+ require 'psych/nodes/alias'
8
+
9
+ module Psych
10
+ ###
11
+ # = Overview
12
+ #
13
+ # When using Psych.load to deserialize a YAML document, the document is
14
+ # translated to an intermediary AST. That intermediary AST is then
15
+ # translated in to a Ruby object graph.
16
+ #
17
+ # In the opposite direction, when using Psych.dump, the Ruby object graph is
18
+ # translated to an intermediary AST which is then converted to a YAML
19
+ # document.
20
+ #
21
+ # Psych::Nodes contains all of the classes that make up the nodes of a YAML
22
+ # AST. You can manually build an AST and use one of the visitors (see
23
+ # Psych::Visitors) to convert that AST to either a YAML document or to a
24
+ # Ruby object graph.
25
+ #
26
+ # Here is an example of building an AST that represents a list with one
27
+ # scalar:
28
+ #
29
+ # # Create our nodes
30
+ # stream = Psych::Nodes::Stream.new
31
+ # doc = Psych::Nodes::Document.new
32
+ # seq = Psych::Nodes::Sequence.new
33
+ # scalar = Psych::Nodes::Scalar.new('foo')
34
+ #
35
+ # # Build up our tree
36
+ # stream.children << doc
37
+ # doc.children << seq
38
+ # seq.children << scalar
39
+ #
40
+ # The stream is the root of the tree. We can then convert the tree to YAML:
41
+ #
42
+ # stream.to_yaml => "---\n- foo\n"
43
+ #
44
+ # Or convert it to Ruby:
45
+ #
46
+ # stream.to_ruby => [["foo"]]
47
+ #
48
+ # == YAML AST Requirements
49
+ #
50
+ # A valid YAML AST *must* have one Psych::Nodes::Stream at the root. A
51
+ # Psych::Nodes::Stream node must have 1 or more Psych::Nodes::Document nodes
52
+ # as children.
53
+ #
54
+ # Psych::Nodes::Document nodes must have one and *only* one child. That child
55
+ # may be one of:
56
+ #
57
+ # * Psych::Nodes::Sequence
58
+ # * Psych::Nodes::Mapping
59
+ # * Psych::Nodes::Scalar
60
+ #
61
+ # Psych::Nodes::Sequence and Psych::Nodes::Mapping nodes may have many
62
+ # children, but Psych::Nodes::Mapping nodes should have an even number of
63
+ # children.
64
+ #
65
+ # All of these are valid children for Psych::Nodes::Sequence and
66
+ # Psych::Nodes::Mapping nodes:
67
+ #
68
+ # * Psych::Nodes::Sequence
69
+ # * Psych::Nodes::Mapping
70
+ # * Psych::Nodes::Scalar
71
+ # * Psych::Nodes::Alias
72
+ #
73
+ # Psych::Nodes::Scalar and Psych::Nodes::Alias are both terminal nodes and
74
+ # should not have any children.
75
+ module Nodes
76
+ end
77
+ end
@@ -0,0 +1,4 @@
1
+ module Psych
2
+ class Omap < ::Hash
3
+ end
4
+ end
@@ -0,0 +1,51 @@
1
+ module Psych
2
+ ###
3
+ # YAML event parser class. This class parses a YAML document and calls
4
+ # events on the handler that is passed to the constructor. The events can
5
+ # be used for things such as constructing a YAML AST or deserializing YAML
6
+ # documents. It can even be fed back to Psych::Emitter to emit the same
7
+ # document that was parsed.
8
+ #
9
+ # See Psych::Handler for documentation on the events that Psych::Parser emits.
10
+ #
11
+ # Here is an example that prints out ever scalar found in a YAML document:
12
+ #
13
+ # # Handler for detecting scalar values
14
+ # class ScalarHandler < Psych::Handler
15
+ # def scalar value, anchor, tag, plain, quoted, style
16
+ # puts value
17
+ # end
18
+ # end
19
+ #
20
+ # parser = Psych::Parser.new(ScalarHandler.new)
21
+ # parser.parse(yaml_document)
22
+ #
23
+ # Here is an example that feeds the parser back in to Psych::Emitter. The
24
+ # YAML document is read from STDIN and written back out to STDERR:
25
+ #
26
+ # parser = Psych::Parser.new(Psych::Emitter.new($stderr))
27
+ # parser.parse($stdin)
28
+ #
29
+ # Psych uses Psych::Parser in combination with Psych::TreeBuilder to
30
+ # construct an AST of the parsed YAML document.
31
+
32
+ class Parser
33
+ class Mark < Struct.new(:index, :line, :column)
34
+ end
35
+
36
+ # The handler on which events will be called
37
+ attr_accessor :handler
38
+
39
+ # Set the encoding for this parser to +encoding+
40
+ attr_writer :external_encoding
41
+
42
+ ###
43
+ # Creates a new Psych::Parser instance with +handler+. YAML events will
44
+ # be called on +handler+. See Psych::Parser for more details.
45
+
46
+ def initialize handler = Handler.new
47
+ @handler = handler
48
+ @external_encoding = ANY
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,149 @@
1
+ require 'strscan'
2
+
3
+ module Psych
4
+ ###
5
+ # Scan scalars for built in types
6
+ class ScalarScanner
7
+ # Taken from http://yaml.org/type/timestamp.html
8
+ TIME = /^\d{4}-\d{1,2}-\d{1,2}([Tt]|\s+)\d{1,2}:\d\d:\d\d(\.\d*)?(\s*Z|[-+]\d{1,2}(:\d\d)?)?/
9
+
10
+ # Taken from http://yaml.org/type/float.html
11
+ FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10)
12
+ |[-+]?[0-9][0-9_,]*(:[0-5]?[0-9])+\.[0-9_]*(?# base 60)
13
+ |[-+]?\.(inf|Inf|INF)(?# infinity)
14
+ |\.(nan|NaN|NAN)(?# not a number))$/x
15
+
16
+ # Taken from http://yaml.org/type/int.html
17
+ INTEGER = /^(?:[-+]?0b[0-1_]+ (?# base 2)
18
+ |[-+]?0[0-7_]+ (?# base 8)
19
+ |[-+]?(?:0|[1-9][0-9_]*) (?# base 10)
20
+ |[-+]?0x[0-9a-fA-F_]+ (?# base 16))$/x
21
+
22
+ attr_reader :class_loader
23
+
24
+ # Create a new scanner
25
+ def initialize class_loader
26
+ @string_cache = {}
27
+ @symbol_cache = {}
28
+ @class_loader = class_loader
29
+ end
30
+
31
+ # Tokenize +string+ returning the ruby object
32
+ def tokenize string
33
+ return nil if string.empty?
34
+ return string if @string_cache.key?(string)
35
+ return @symbol_cache[string] if @symbol_cache.key?(string)
36
+
37
+ case string
38
+ # Check for a String type, being careful not to get caught by hash keys, hex values, and
39
+ # special floats (e.g., -.inf).
40
+ when /^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/
41
+ if string.length > 5
42
+ @string_cache[string] = true
43
+ return string
44
+ end
45
+
46
+ case string
47
+ when /^[^ytonf~]/i
48
+ @string_cache[string] = true
49
+ string
50
+ when '~', /^null$/i
51
+ nil
52
+ when /^(yes|true|on)$/i
53
+ true
54
+ when /^(no|false|off)$/i
55
+ false
56
+ else
57
+ @string_cache[string] = true
58
+ string
59
+ end
60
+ when TIME
61
+ begin
62
+ parse_time string
63
+ rescue ArgumentError
64
+ string
65
+ end
66
+ when /^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/
67
+ require 'date'
68
+ begin
69
+ class_loader.date.strptime(string, '%Y-%m-%d')
70
+ rescue ArgumentError
71
+ string
72
+ end
73
+ when /^\.inf$/i
74
+ Float::INFINITY
75
+ when /^-\.inf$/i
76
+ -Float::INFINITY
77
+ when /^\.nan$/i
78
+ Float::NAN
79
+ when /^:./
80
+ if string =~ /^:(["'])(.*)\1/
81
+ @symbol_cache[string] = class_loader.symbolize($2.sub(/^:/, ''))
82
+ else
83
+ @symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, ''))
84
+ end
85
+ when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/
86
+ i = 0
87
+ string.split(':').each_with_index do |n,e|
88
+ i += (n.to_i * 60 ** (e - 2).abs)
89
+ end
90
+ i
91
+ when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*$/
92
+ i = 0
93
+ string.split(':').each_with_index do |n,e|
94
+ i += (n.to_f * 60 ** (e - 2).abs)
95
+ end
96
+ i
97
+ when FLOAT
98
+ if string == '.'
99
+ @string_cache[string] = true
100
+ string
101
+ else
102
+ Float(string.gsub(/[,_]|\.$/, ''))
103
+ end
104
+ else
105
+ int = parse_int string.gsub(/[,_]/, '')
106
+ return int if int
107
+
108
+ @string_cache[string] = true
109
+ string
110
+ end
111
+ end
112
+
113
+ ###
114
+ # Parse and return an int from +string+
115
+ def parse_int string
116
+ return unless INTEGER === string
117
+ Integer(string)
118
+ end
119
+
120
+ ###
121
+ # Parse and return a Time from +string+
122
+ def parse_time string
123
+ klass = class_loader.load 'Time'
124
+
125
+ date, time = *(string.split(/[ tT]/, 2))
126
+ (yy, m, dd) = date.split('-').map { |x| x.to_i }
127
+ md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/)
128
+
129
+ (hh, mm, ss) = md[1].split(':').map { |x| x.to_i }
130
+ us = (md[2] ? Rational("0.#{md[2]}") : 0) * 1000000
131
+
132
+ time = klass.utc(yy, m, dd, hh, mm, ss, us)
133
+
134
+ return time if 'Z' == md[3]
135
+ return klass.at(time.to_i, us) unless md[3]
136
+
137
+ tz = md[3].match(/^([+\-]?\d{1,2})\:?(\d{1,2})?$/)[1..-1].compact.map { |digit| Integer(digit, 10) }
138
+ offset = tz.first * 3600
139
+
140
+ if offset < 0
141
+ offset -= ((tz[1] || 0) * 60)
142
+ else
143
+ offset += ((tz[1] || 0) * 60)
144
+ end
145
+
146
+ klass.at((time - offset).to_i, us)
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,4 @@
1
+ module Psych
2
+ class Set < ::Hash
3
+ end
4
+ end