Class: FactoryDataPreloader::FactoryData
- Extended by:
- DataMethods
- Defined in:
- lib/factory_data_preloader/factory_data.rb
Constant Summary collapse
- @@single_test_cache =
{}
Class Attribute Summary collapse
-
.definition_file_paths ⇒ Object
An Array of strings specifying locations that should be searched for factory_data definitions.
Class Method Summary collapse
- .delete_preload_data! ⇒ Object
- .find_definitions ⇒ Object
- .preload(model_type, options = {}, &proc) ⇒ Object
- .preload_data! ⇒ Object
- .reset_cache! ⇒ Object
Class Attribute Details
.definition_file_paths ⇒ Object
An Array of strings specifying locations that should be searched for factory_data definitions. By default, factory_data_preloader will attempt to require “factory_data,” “test/factory_data,” and “spec/factory_data.” Only the first existing file will be loaded.
22 23 24 |
# File 'lib/factory_data_preloader/factory_data.rb', line 22 def definition_file_paths @definition_file_paths end |
Class Method Details
.delete_preload_data! ⇒ Object
38 39 40 41 42 43 |
# File 'lib/factory_data_preloader/factory_data.rb', line 38 def delete_preload_data! # Delete them in the reverse order of the dependencies, to handle foreign keys FactoryDataPreloader.requested_preloaders.dependency_order.reverse.each do |preloader| preloader.delete_table_data! end end |
.find_definitions ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/factory_data_preloader/factory_data.rb', line 55 def find_definitions definition_file_paths.each do |path| require("#{path}.rb") if File.exists?("#{path}.rb") if File.directory? path Dir[File.join(path, '*.rb')].each do |file| require file end end end end |
.preload(model_type, options = {}, &proc) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/factory_data_preloader/factory_data.rb', line 24 def preload(model_type, = {}, &proc) if existing_preloader = AllPreloaders.instance.from_symbol(model_type, false) existing_preloader.remove! end FactoryDataPreloader::Preloader.new(model_type, [:model_class], proc, [:depends_on]) DataMethods.class_eval do define_method model_type do |key| FactoryData.send(:get_record, model_type, key) end end end |
.preload_data! ⇒ Object
45 46 47 48 49 |
# File 'lib/factory_data_preloader/factory_data.rb', line 45 def preload_data! FactoryDataPreloader.requested_preloaders.dependency_order.each do |preloader| preloader.preload! end end |
.reset_cache! ⇒ Object
51 52 53 |
# File 'lib/factory_data_preloader/factory_data.rb', line 51 def reset_cache! @@single_test_cache = {} end |