# File lib/active_record/fixtures/file.rb, line 23 23: def initialize(file) 24: @file = file 25: @rows = nil 26: end
Open a fixture file named file. When called with a block, the block is called with the filehandle and the filehandle is automatically closed when the block finishes.
# File lib/active_record/fixtures/file.rb, line 18 18: def self.open(file) 19: x = new file 20: block_given? ? yield(x) : x 21: end
# File lib/active_record/fixtures/file.rb, line 50 50: def render(content) 51: ERB.new(content).result 52: end
# File lib/active_record/fixtures/file.rb, line 39 39: def rows 40: return @rows if @rows 41: 42: begin 43: data = YAML.load(render(IO.read(@file))) 44: rescue *RESCUE_ERRORS => error 45: 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 46: end 47: @rows = data ? validate(data).to_a : [] 48: end
Validate our unmarshalled data.
# File lib/active_record/fixtures/file.rb, line 55 55: def validate(data) 56: unless Hash === data || YAML::Omap === data 57: raise Fixture::FormatError, 'fixture is not a hash' 58: end 59: 60: raise Fixture::FormatError unless data.all? { |name, row| Hash === row } 61: data 62: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.