diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-31 09:46:52 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-31 10:01:59 -0700 |
commit | 5f690b97ba0dc411efc59789ad777c61cad198ae (patch) | |
tree | 54eec2f96060603ea761d1cecb3f693bf145987d /activerecord/lib | |
parent | da048de773cea8a970768f04cecd0b3dbb015772 (diff) | |
download | rails-5f690b97ba0dc411efc59789ad777c61cad198ae.tar.gz rails-5f690b97ba0dc411efc59789ad777c61cad198ae.tar.bz2 rails-5f690b97ba0dc411efc59789ad777c61cad198ae.zip |
Psych is always available on 1.9
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/coders/yaml_column.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/fixtures/file.rb | 44 |
2 files changed, 23 insertions, 29 deletions
diff --git a/activerecord/lib/active_record/coders/yaml_column.rb b/activerecord/lib/active_record/coders/yaml_column.rb index 66a0c83c41..f17e7158de 100644 --- a/activerecord/lib/active_record/coders/yaml_column.rb +++ b/activerecord/lib/active_record/coders/yaml_column.rb @@ -1,12 +1,10 @@ +require 'yaml' + module ActiveRecord # :stopdoc: module Coders class YAMLColumn - RESCUE_ERRORS = [ ArgumentError ] - - if defined?(Psych) && defined?(Psych::SyntaxError) - RESCUE_ERRORS << Psych::SyntaxError - end + RESCUE_ERRORS = [ ArgumentError, Psych::SyntaxError ] attr_accessor :object_class diff --git a/activerecord/lib/active_record/fixtures/file.rb b/activerecord/lib/active_record/fixtures/file.rb index 6547791144..a9cabf5a7b 100644 --- a/activerecord/lib/active_record/fixtures/file.rb +++ b/activerecord/lib/active_record/fixtures/file.rb @@ -24,37 +24,33 @@ module ActiveRecord rows.each(&block) end - RESCUE_ERRORS = [ ArgumentError ] # :nodoc: + RESCUE_ERRORS = [ ArgumentError, Psych::SyntaxError ] # :nodoc: private - if defined?(Psych) && defined?(Psych::SyntaxError) - RESCUE_ERRORS << Psych::SyntaxError - end - - def rows - return @rows if @rows + def rows + return @rows if @rows + + begin + data = YAML.load(render(IO.read(@file))) + rescue *RESCUE_ERRORS => error + raise Fixture::FormatError, "a YAML error occurred parsing #{@file}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{error.class}: #{error}", error.backtrace + end + @rows = data ? validate(data).to_a : [] + end - begin - data = YAML.load(render(IO.read(@file))) - rescue *RESCUE_ERRORS => error - raise Fixture::FormatError, "a YAML error occurred parsing #{@file}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{error.class}: #{error}", error.backtrace + def render(content) + ERB.new(content).result end - @rows = data ? validate(data).to_a : [] - end - def render(content) - ERB.new(content).result - end + # Validate our unmarshalled data. + def validate(data) + unless Hash === data || YAML::Omap === data + raise Fixture::FormatError, 'fixture is not a hash' + end - # Validate our unmarshalled data. - def validate(data) - unless Hash === data || YAML::Omap === data - raise Fixture::FormatError, 'fixture is not a hash' + raise Fixture::FormatError unless data.all? { |name, row| Hash === row } + data end - - raise Fixture::FormatError unless data.all? { |name, row| Hash === row } - data - end end end end |