class Kibutsu::FixtureLoader
Loads fixtures from files, optionally with ERB pre-processing and creates Fixture
objects from them.
Attributes
database_connection[R]
fixture_file_path[R]
Public Class Methods
new(fixture_file_path, database_connection)
click to toggle source
# File lib/kibutsu/fixture_loader.rb, line 11 def initialize(fixture_file_path, database_connection) @fixture_file_path = fixture_file_path @database_connection = database_connection end
Public Instance Methods
load_fixture_tables()
click to toggle source
# File lib/kibutsu/fixture_loader.rb, line 16 def load_fixture_tables file_content = File.read(fixture_file_path) yaml_content = if fixture_file_path.end_with? '.yml.erb' run_erb(file_content) else file_content end fixtures_hash = load_fixture(yaml_content) build_fixture_tables(fixtures_hash) end
Private Instance Methods
build_fixture_tables(fixtures_hash)
click to toggle source
# File lib/kibutsu/fixture_loader.rb, line 31 def build_fixture_tables(fixtures_hash) fixtures_hash.map do |table_name, fixtures| table = Kibutsu::FixtureWorld.instance.find_table(table_name) raise "Couldn't find table with name #{table_name}" if table.nil? fixtures.each do |fixture_name, attributes| table << Kibutsu::Fixture.new(table, fixture_name, attributes) end table end end
load_fixture(yaml_content)
click to toggle source
# File lib/kibutsu/fixture_loader.rb, line 48 def load_fixture(yaml_content) YAML.safe_load(yaml_content) end
run_erb(file_content)
click to toggle source
# File lib/kibutsu/fixture_loader.rb, line 44 def run_erb(file_content) ERB.new(file_content).result(binding) end