Skip to content
This repository
Browse code

Psych is always available on 1.9

  • Loading branch information...
commit 5f690b97ba0dc411efc59789ad777c61cad198ae 1 parent da048de
Jeremy Kemper authored May 31, 2012
8  activerecord/lib/active_record/coders/yaml_column.rb
... ...
@@ -1,12 +1,10 @@
  1
+require 'yaml'
  2
+
1 3
 module ActiveRecord
2 4
   # :stopdoc:
3 5
   module Coders
4 6
     class YAMLColumn
5  
-      RESCUE_ERRORS = [ ArgumentError ]
6  
-
7  
-      if defined?(Psych) && defined?(Psych::SyntaxError)
8  
-        RESCUE_ERRORS << Psych::SyntaxError
9  
-      end
  7
+      RESCUE_ERRORS = [ ArgumentError, Psych::SyntaxError ]
10 8
 
11 9
       attr_accessor :object_class
12 10
 
44  activerecord/lib/active_record/fixtures/file.rb
@@ -24,37 +24,33 @@ def each(&block)
24 24
         rows.each(&block)
25 25
       end
26 26
 
27  
-      RESCUE_ERRORS = [ ArgumentError ] # :nodoc:
  27
+      RESCUE_ERRORS = [ ArgumentError, Psych::SyntaxError ] # :nodoc:
28 28
 
29 29
       private
30  
-      if defined?(Psych) && defined?(Psych::SyntaxError)
31  
-        RESCUE_ERRORS << Psych::SyntaxError
32  
-      end
33  
-
34  
-      def rows
35  
-        return @rows if @rows
  30
+        def rows
  31
+          return @rows if @rows
  32
+
  33
+          begin
  34
+            data = YAML.load(render(IO.read(@file)))
  35
+          rescue *RESCUE_ERRORS => error
  36
+            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
  37
+          end
  38
+          @rows = data ? validate(data).to_a : []
  39
+        end
36 40
 
37  
-        begin
38  
-          data = YAML.load(render(IO.read(@file)))
39  
-        rescue *RESCUE_ERRORS => error
40  
-          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
  41
+        def render(content)
  42
+          ERB.new(content).result
41 43
         end
42  
-        @rows = data ? validate(data).to_a : []
43  
-      end
44 44
 
45  
-      def render(content)
46  
-        ERB.new(content).result
47  
-      end
  45
+        # Validate our unmarshalled data.
  46
+        def validate(data)
  47
+          unless Hash === data || YAML::Omap === data
  48
+            raise Fixture::FormatError, 'fixture is not a hash'
  49
+          end
48 50
 
49  
-      # Validate our unmarshalled data.
50  
-      def validate(data)
51  
-        unless Hash === data || YAML::Omap === data
52  
-          raise Fixture::FormatError, 'fixture is not a hash'
  51
+          raise Fixture::FormatError unless data.all? { |name, row| Hash === row }
  52
+          data
53 53
         end
54  
-
55  
-        raise Fixture::FormatError unless data.all? { |name, row| Hash === row }
56  
-        data
57  
-      end
58 54
     end
59 55
   end
60 56
 end

1 note on commit 5f690b9

Chris Gaffney

I believe it's still possible to build 1.9.3 without Psych if you don't have libyaml installed.

Please sign in to comment.
Something went wrong with that request. Please try again.