Class: FixtureKit::Cache
- Inherits:
-
Object
- Object
- FixtureKit::Cache
- Includes:
- ConfigurationHelper
- Defined in:
- lib/fixture_kit/cache.rb
Constant Summary collapse
- ANONYMOUS_DIRECTORY =
"_anonymous"
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#fixture ⇒ Object
readonly
Returns the value of attribute fixture.
Instance Method Summary collapse
- #clear_memory ⇒ Object
- #exists? ⇒ Boolean
- #identifier ⇒ Object
-
#initialize(fixture) ⇒ Cache
constructor
A new instance of Cache.
- #load ⇒ Object
- #path ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(fixture) ⇒ Cache
Returns a new instance of Cache.
11 12 13 |
# File 'lib/fixture_kit/cache.rb', line 11 def initialize(fixture) @fixture = fixture end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/fixture_kit/cache.rb', line 9 def content @content end |
#fixture ⇒ Object (readonly)
Returns the value of attribute fixture.
9 10 11 |
# File 'lib/fixture_kit/cache.rb', line 9 def fixture @fixture end |
Instance Method Details
#clear_memory ⇒ Object
34 35 36 |
# File 'lib/fixture_kit/cache.rb', line 34 def clear_memory @content = nil end |
#exists? ⇒ Boolean
30 31 32 |
# File 'lib/fixture_kit/cache.rb', line 30 def exists? content || file_cache.exists? end |
#identifier ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fixture_kit/cache.rb', line 19 def identifier @identifier ||= begin raw_identifier = fixture.identifier if raw_identifier.is_a?(String) raw_identifier else File.join(ANONYMOUS_DIRECTORY, FixtureKit.runner.adapter.identifier_for(raw_identifier)) end end end |
#load ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fixture_kit/cache.rb', line 38 def load unless exists? raise FixtureKit::CacheMissingError, "Cache does not exist for fixture '#{fixture.identifier}'" end @content ||= file_cache.read FixtureKit.runner.coders.each do |coder| coder.mount(content.data_for(coder.class)) end Repository.new(content.exposed) end |
#path ⇒ Object
15 16 17 |
# File 'lib/fixture_kit/cache.rb', line 15 def path file_cache.path end |
#save ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fixture_kit/cache.rb', line 52 def save FixtureKit.runner.adapter.execute do |context| @content = MemoryCache.new( data: evaluate(FixtureKit.runner.coders, context), exposed: file_cache.serialize_exposed(fixture.definition.exposed) ) end file_cache.write(content) end |