Skip to content

Commit

Permalink
Merge e8db786 into 02c7032
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmo committed Oct 8, 2013
2 parents 02c7032 + e8db786 commit 792320c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'https://rubygems.org'

gem 'rake'

platforms :ruby do
platforms :ruby, :mingw do
gem 'sqlite3'
end

Expand Down
9 changes: 7 additions & 2 deletions lib/delayed/psych_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def visit_Class(klass)
end

class ToRuby
def visit_Psych_Nodes_Scalar(o)
original_visit_Psych_Nodes_Scalar_method = instance_method(:visit_Psych_Nodes_Scalar)

define_method(:visit_Psych_Nodes_Scalar) do |o|
@st[o.anchor] = o.value if o.anchor

if klass = Psych.load_tags[o.tag]
Expand All @@ -57,6 +59,9 @@ def visit_Psych_Nodes_Scalar(o)
case o.tag
when '!binary', 'tag:yaml.org,2002:binary'
o.value.unpack('m').first
when '!ruby/object:BigDecimal'
require 'bigdecimal'
BigDecimal._load o.value
when '!str', 'tag:yaml.org,2002:str'
o.value
when "!ruby/object:DateTime"
Expand Down Expand Up @@ -94,7 +99,7 @@ def visit_Psych_Nodes_Scalar(o)
when /^!ruby\/sym(bol)?:?(.*)?$/
o.value.to_sym
else
@ss.tokenize o.value
original_visit_Psych_Nodes_Scalar_method.bind(self).call o
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/delayed/psych_ext_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'helper'

describe 'Psych::Visitors::ToRuby', :if => defined?(Psych::Visitors::ToRuby) do
context BigDecimal do
it 'deserializes correctly' do
deserialized = YAML.load("--- !ruby/object:BigDecimal 18:0.1337E2\n...\n")

expect(deserialized).to be_an_instance_of(BigDecimal)
expect(deserialized).to eq(BigDecimal('13.37'))
end
end
end
4 changes: 3 additions & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
require 'simplecov'
require 'coveralls'

require 'tempfile'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start

Delayed::Worker.logger = Logger.new('/tmp/dj.log')
Delayed::Worker.logger = Logger.new(Tempfile.new('dj.log'))
ENV['RAILS_ENV'] = 'test'

Delayed::Worker.backend = :test
Expand Down

0 comments on commit 792320c

Please sign in to comment.