class FixtureOverlord::ReadFixture
Public Class Methods
new(file)
click to toggle source
# File lib/fixture_overlord/read_fixture.rb, line 13 def initialize(file) @file = file end
Public Instance Methods
read(key = nil)
click to toggle source
# File lib/fixture_overlord/read_fixture.rb, line 17 def read(key = nil) hash = read_file hash = hash[key.to_s] unless key.nil? Hashish[hash].symbolize_keys end
Private Instance Methods
erb_render(content)
click to toggle source
# File lib/fixture_overlord/read_fixture.rb, line 54 def erb_render(content) ::ERB.new(content).result end
read_file()
click to toggle source
CREDIT: The next three methods are almost identitical to those within Rails'
ActiveRecord FixtureSet::File
github.com/rails/rails/blob/master/activerecord/lib/active_record/fixture_set/file.rb
# File lib/fixture_overlord/read_fixture.rb, line 30 def read_file begin data = ::YAML.load(render) rescue ::ArgumentError, ::Psych::SyntaxError => error raise FormattingError, "a YAML error ocurred parsing #{@file}.\nThe error was:\n #{error.class}: #{error}", error.backtrace end validate(data) end
render()
click to toggle source
# File lib/fixture_overlord/read_fixture.rb, line 48 def render erb_render( IO.read(@file) ) end
valid_data?(data)
click to toggle source
# File lib/fixture_overlord/read_fixture.rb, line 58 def valid_data?(data) ::Hash === data || ::YAML::Omap === data end
validate(data)
click to toggle source
# File lib/fixture_overlord/read_fixture.rb, line 39 def validate(data) unless valid_data?(data) raise FormattingError, "fixture is not a Hash or YAML::Omap." end raise FormattingError unless data.all? { |name, row| ::Hash === row } data end