Skip to content

Commit

Permalink
Allow to pass IO to from_yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and asterite committed Dec 12, 2016
1 parent a34f32f commit a7135c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions spec/std/yaml/serialization_spec.cr
Expand Up @@ -46,6 +46,11 @@ describe "YAML serialization" do
Array(Int32).from_yaml("---\n- 1\n- 2\n- 3\n").should eq([1, 2, 3])
end

it "does Array#from_yaml from IO" do
io = IO::Memory.new "---\n- 1\n- 2\n- 3\n"
Array(Int32).from_yaml(io).should eq([1, 2, 3])
end

it "does Array#from_yaml with block" do
elements = [] of Int32
Array(Int32).from_yaml("---\n- 1\n- 2\n- 3\n") do |element|
Expand Down
8 changes: 4 additions & 4 deletions src/yaml/from_yaml.cr
@@ -1,5 +1,5 @@
def Object.from_yaml(string : String) : self
YAML::PullParser.new(string) do |parser|
def Object.from_yaml(string_or_io) : self
YAML::PullParser.new(string_or_io) do |parser|
parser.read_stream do
parser.read_document do
new parser
Expand All @@ -8,8 +8,8 @@ def Object.from_yaml(string : String) : self
end
end

def Array.from_yaml(string : String)
YAML::PullParser.new(string) do |parser|
def Array.from_yaml(string_or_io)
YAML::PullParser.new(string_or_io) do |parser|
parser.read_stream do
parser.read_document do
new(parser) do |element|
Expand Down

0 comments on commit a7135c8

Please sign in to comment.