# File lib/active_record/fixtures.rb, line 848 def fixtures(*table_names) if table_names.first == :all table_names = Dir["#{fixture_path}/**/*.{yml,csv}"] table_names.map! { |f| f[(fixture_path.size + 1)..-5] } else table_names = table_names.flatten.map { |n| n.to_s } end self.fixture_table_names |= table_names require_fixture_classes(table_names) setup_fixture_accessors(table_names) end
# File lib/active_record/fixtures.rb, line 873 def require_fixture_classes(table_names = nil) (table_names || fixture_table_names).each do |table_name| file_name = table_name.to_s file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names try_to_load_dependency(file_name) end end
# File lib/active_record/fixtures.rb, line 844 def set_fixture_class(class_names = {}) self.fixture_class_names = self.fixture_class_names.merge(class_names) end
# File lib/active_record/fixtures.rb, line 881 def setup_fixture_accessors(table_names = nil) table_names = Array.wrap(table_names || fixture_table_names) table_names.each do |table_name| table_name = table_name.to_s.tr('./', '_') redefine_method(table_name) do |*fixtures| force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload @fixture_cache[table_name] ||= {} instances = fixtures.map do |fixture| @fixture_cache[table_name].delete(fixture) if force_reload if @loaded_fixtures[table_name][fixture.to_s] @fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find else raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'" end end instances.size == 1 ? instances.first : instances end private table_name end end
# File lib/active_record/fixtures.rb, line 861 def try_to_load_dependency(file_name) require_dependency file_name rescue LoadError => e # Let's hope the developer has included it himself # Let's warn in case this is a subdependency, otherwise # subdependency error messages are totally cryptic if ActiveRecord::Base.logger ActiveRecord::Base.logger.warn("Unable to load #{file_name}, underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}") end end
Generated with the Darkfish Rdoc Generator 2.