psych-simple 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/psych/simple.rb +26 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46925684618841d0fedcff982e85391d3f117952
|
4
|
+
data.tar.gz: cde4c99de716a9e1fef0bcd1b45d8b8cbd65e628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85c0c3ea612897fda59b767407e1544635d10db6b983a428fba0dc120b8dce4375f291448ddcee61f1ece3934949528a7e90298f52b07429b5e21b5d61d6205f
|
7
|
+
data.tar.gz: 7874febe0e2da19d8d5c21b8d7dfafd3a7000fb9924bb82d6b206481c85d9e67d4249bbf0fabe57ff7bb62429f13d207265065478a102d062f47a8b9d518d8e9
|
data/lib/psych/simple.rb
CHANGED
@@ -1,15 +1,32 @@
|
|
1
1
|
require 'psych'
|
2
2
|
|
3
3
|
module Psych
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
# Load yaml in to a ruby data structure.
|
6
|
+
#
|
7
|
+
# This function is 2-5x faster as compared to Psych::load but supports a
|
8
|
+
# simplified (and safe) data format only. All values are deserialized as
|
9
|
+
# strings. Anchors and tags are not supported, and thus ruby objects are
|
10
|
+
# not supported either.
|
11
|
+
#
|
12
|
+
# Options can have the following keys,
|
13
|
+
# - filename: used in the exception message (defaults to nil)
|
14
|
+
# - symbolize_names: if true return symbols as keys in a yaml mapping,
|
15
|
+
# otherwise strings are returned (defaults to false)
|
16
|
+
#
|
17
|
+
def self.simple_load(yaml, options = nil)
|
18
|
+
parser = Parser.new(SimpleHandler.new(options))
|
19
|
+
parser.parse yaml, options && options[:filename]
|
7
20
|
parser.handler.document
|
8
21
|
end
|
9
22
|
|
10
23
|
class SimpleHandler
|
11
24
|
attr_reader :document
|
12
25
|
|
26
|
+
def initialize(options = nil)
|
27
|
+
@symbolize_names = options && options[:symbolize_names]
|
28
|
+
end
|
29
|
+
|
13
30
|
def start_stream(encoding)
|
14
31
|
@stack = Array.new
|
15
32
|
end
|
@@ -18,7 +35,7 @@ module Psych
|
|
18
35
|
raise unless @stack.empty?
|
19
36
|
end
|
20
37
|
|
21
|
-
def start_document
|
38
|
+
def start_document(version, tag_directives, implicit)
|
22
39
|
raise unless tag_directives.empty?
|
23
40
|
@stack.push Array.new
|
24
41
|
end
|
@@ -33,7 +50,11 @@ module Psych
|
|
33
50
|
end
|
34
51
|
|
35
52
|
def end_mapping
|
36
|
-
mapping = Hash
|
53
|
+
mapping = Hash.new
|
54
|
+
@stack.pop.each_slice(2) do |name, value|
|
55
|
+
name = name.to_sym if @symbolize_names
|
56
|
+
mapping[name] = value
|
57
|
+
end
|
37
58
|
@stack.last << mapping
|
38
59
|
end
|
39
60
|
|