Class: FixtureKit::Fixture

Inherits:
Object
  • Object
show all
Includes:
ConfigurationHelper
Defined in:
lib/fixture_kit/fixture.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, definition) ⇒ Fixture

Returns a new instance of Fixture.



11
12
13
14
15
16
17
18
19
# File 'lib/fixture_kit/fixture.rb', line 11

def initialize(identifier, definition)
  @identifier = identifier
  @definition = definition
  @cache = Cache.new(self)

  if definition.extends
    @parent = FixtureKit.runner.registry.add(definition.extends)
  end
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



9
10
11
# File 'lib/fixture_kit/fixture.rb', line 9

def cache
  @cache
end

#definitionObject (readonly)

Returns the value of attribute definition.



9
10
11
# File 'lib/fixture_kit/fixture.rb', line 9

def definition
  @definition
end

#identifierObject (readonly)

Returns the value of attribute identifier.



9
10
11
# File 'lib/fixture_kit/fixture.rb', line 9

def identifier
  @identifier
end

#parentObject (readonly)

Returns the value of attribute parent.



9
10
11
# File 'lib/fixture_kit/fixture.rb', line 9

def parent
  @parent
end

Instance Method Details

#finishObject



39
40
41
# File 'lib/fixture_kit/fixture.rb', line 39

def finish
  @cache.clear_memory if anonymous?
end

#generate(force: false) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/fixture_kit/fixture.rb', line 21

def generate(force: false)
  return if @cache.exists? && !force

  parent&.generate

  emit(:cache_save)
  emit(:cache_saved) { @cache.save }
end

#mountObject



30
31
32
33
34
35
36
37
# File 'lib/fixture_kit/fixture.rb', line 30

def mount
  unless @cache.exists?
    raise FixtureKit::CacheMissingError, "Cache does not exist for fixture '#{identifier}'"
  end

  emit(:cache_mount)
  emit(:cache_mounted) { @cache.load }
end