Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def accept target
if @domain_types.key? key
value, block = @domain_types[key]
result = block.call value, result
register(target, result)
end
end

Expand Down
22 changes: 22 additions & 0 deletions test/psych/test_psych.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ def test_domain_types
assert_equal({ 'hello' => 'world' }, got)
end

def test_domain_types_with_aliases
my_test_class = Struct.new(:prop1, :prop2)

Psych.add_domain_type('test/custom_yaml', 'my_test_object') do |type, value|
my_test_class.new(prop1: value['prop1'], prop2: value['prop2'])
end

yaml = <<-eoyml
---
object1: &1 !test/custom_yaml:my_test_object
prop1: 13
prop2: 1989
object2: *1
object3: *1
eoyml

data = Psych.load(yaml, aliases: true)
assert_equal(my_test_class.new(prop1: 13, prop2: 1989), data['object1'])
assert_equal(my_test_class.new(prop1: 13, prop2: 1989), data['object2'])
assert_equal(my_test_class.new(prop1: 13, prop2: 1989), data['object3'])
end

def test_load_freeze
data = Psych.load("--- {foo: ['a']}", freeze: true)
assert_predicate data, :frozen?
Expand Down
Loading