Module: FixtureRecord

Extended by:
ActiveSupport::Concern
Includes:
AssociationTraversal, BelongsToUpdation, FilterableAttributes, Naming, Sanitizable
Defined in:
lib/fixture_record.rb,
lib/fixture_record/cache.rb,
lib/fixture_record/naming.rb,
lib/fixture_record/railtie.rb,
lib/fixture_record/version.rb,
lib/fixture_record/belongs_to_updation.rb,
lib/fixture_record/association_traversal.rb,
lib/fixture_record/filterable_attributes.rb,
lib/fixture_record/sanitizers/simple_timestamp.rb

Defined Under Namespace

Modules: AssociationTraversal, BelongsToUpdation, FilterableAttributes, Generators, Naming, Sanitizable, Sanitizers Classes: Cache, Data, Railtie

Constant Summary collapse

Sanitizer =
FixtureRecord::Sanitizable::Base
VERSION =
"1.0"

Instance Attribute Summary

Attributes included from AssociationTraversal

#_traversed_fixture_record_associations

Attributes included from Naming

#fixture_record_prefix, #fixture_record_suffix

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BelongsToUpdation

#update_belongs_to_fixture_record_associations

Methods included from Sanitizable

#sanitize_attributes_for_fxiture_record, #sanitize_value_for_test_fixture

Methods included from FilterableAttributes

#filter_attributes_for_fxiture_record

Methods included from AssociationTraversal

#traverse_fixture_record_associations

Methods included from Naming

#test_fixture_name

Class Method Details

.base_pathObject



48
49
50
# File 'lib/fixture_record.rb', line 48

def base_path
  @@base_path.is_a?(String) ? @@base_path : @@base_path.call
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (FixtureRecord)

    the object that the method was called on



44
45
46
# File 'lib/fixture_record.rb', line 44

def configure
  yield self
end

.lock!(owner) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/fixture_record.rb', line 63

def lock!(owner)
  return if locked?

  @@_locked_by = owner
  @@cache = FixtureRecord::Cache.new
  @@data = FixtureRecord::Data.new
end

.locked?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fixture_record.rb', line 71

def locked?
  @@_locked_by.present?
end

.locked_by?(owner) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/fixture_record.rb', line 85

def locked_by?(owner)
  @@_locked_by == owner
end

.name_handler=(proc_or_klass) ⇒ Object



52
53
54
# File 'lib/fixture_record.rb', line 52

def name_handler=(proc_or_klass)
  @@name_handler = proc_or_klass.is_a?(Class) ? proc_or_klass.new : proc_or_klass
end

.registryObject



89
90
91
# File 'lib/fixture_record.rb', line 89

def registry
  FixtureRecord::Sanitizable::Registry
end

.release!(owner) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/fixture_record.rb', line 75

def release!(owner)
  if locked_by?(owner)
    @@_locked_by = nil
    @@_cache = nil
    true
  else
    false
  end
end

.sanitize_column_regex(col_regex, with:) ⇒ Object



56
57
58
59
60
61
# File 'lib/fixture_record.rb', line 56

def sanitize_column_regex(col_regex, with:)
  registry_name_or_klass = with
  klass = registry_name_or_klass.is_a?(Symbol) ? FixtureRecord.registry[registry_name_or_klass] : registry_name_or_klass
  klass_instance = klass.is_a?(Class) ? klass.new : klass
  FixtureRecord.registry.sanitize_pattern col_regex, with: klass_instance
end

Instance Method Details

#to_fixture_record(*associations) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/fixture_record.rb', line 33

def to_fixture_record(*associations)
  FixtureRecord.lock!(self)
  FixtureRecord.cache[self.test_fixture_name] ||= self
  traverse_fixture_record_associations(*associations)
  FixtureRecord.cache.dump! if  FixtureRecord.locked_by?(self)
ensure
  FixtureRecord.release!(self)
end