Module: DumpedRailers

Extended by:
Configuration
Defined in:
lib/dumped_railers.rb,
lib/dumped_railers/dump.rb,
lib/dumped_railers/import.rb,
lib/dumped_railers/version.rb,
lib/dumped_railers/file_helper.rb,
lib/dumped_railers/configuration.rb,
lib/dumped_railers/fixture_builder/model.rb,
lib/dumped_railers/fixture_builder/record.rb,
lib/dumped_railers/record_builder/fixture_row.rb,
lib/dumped_railers/record_builder/fixture_set.rb,
lib/dumped_railers/record_builder/fixture_table.rb,
lib/dumped_railers/preprocessor/strip_ignorables.rb,
lib/dumped_railers/record_builder/dependency_tracker.rb

Defined Under Namespace

Modules: Configuration, FileHelper, FixtureBuilder, Preprocessor, RecordBuilder Classes: Dump, Import

Constant Summary collapse

VERSION =
'0.6.0'

Constants included from Configuration

Configuration::IGNORABLE_COLUMNS

Class Method Summary collapse

Methods included from Configuration

configure, configure_defaults!, options

Class Method Details

.dump!(*models, base_dir: nil, preprocessors: nil, ignorable_columns: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dumped_railers.rb', line 13

def dump!(*models, base_dir: nil, preprocessors: nil, ignorable_columns: nil)
  # override global config settings when options are specified
  runtime_options = { preprocessors: preprocessors.presence, ignorable_columns: ignorable_columns.presence }.compact.reverse_merge(dump_options.deep_dup)
  runtime_options[:preprocessors].unshift(
    default_preprocessor(runtime_options[:ignorable_columns])
  )

  fixture_handler = Dump.new(*models, preprocessors: runtime_options[:preprocessors])
  fixtures = fixture_handler.build_fixtures!
  fixture_handler.persist_all!(base_dir)

  fixtures
end

.import!(*paths, authorized_models: nil, before_save: nil, after_save: nil, yaml_column_permitted_classes: []) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dumped_railers.rb', line 27

def import!(*paths, authorized_models: nil, before_save: nil, after_save: nil, yaml_column_permitted_classes: [])
  # make sure class-baseed caches starts with clean state
  DumpedRailers::RecordBuilder::FixtureRow::RecordStore.clear!
  DumpedRailers::RecordBuilder::DependencyTracker.clear!

  # override global config settings when options are specified
  runtime_options = 
    {
      authorized_models: authorized_models.presence,
      yaml_column_permitted_classes: yaml_column_permitted_classes.presence,
    }
    .compact
    .reverse_merge(import_options)

  before_save = Array(before_save).compact
  after_save  = Array(after_save).compact

  fixture_handler = Import.new(
    *paths,
    authorized_models: runtime_options[:authorized_models],
    before_save: before_save,
    after_save:  after_save,
    yaml_column_permitted_classes: runtime_options[:yaml_column_permitted_classes]
  )
  fixture_handler.import_all!
end