Class: FixtureKit::Cache
- Inherits:
-
Object
- Object
- FixtureKit::Cache
- Includes:
- ConfigurationHelper
- Defined in:
- lib/fixture_kit/cache.rb
Constant Summary collapse
- ANONYMOUS_DIRECTORY =
"_anonymous"- DIGEST_LENGTH =
12
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.
14 15 16 |
# File 'lib/fixture_kit/cache.rb', line 14 def initialize(fixture) @fixture = fixture end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/fixture_kit/cache.rb', line 12 def content @content end |
#fixture ⇒ Object (readonly)
Returns the value of attribute fixture.
12 13 14 |
# File 'lib/fixture_kit/cache.rb', line 12 def fixture @fixture end |
Instance Method Details
#clear_memory ⇒ Object
38 39 40 |
# File 'lib/fixture_kit/cache.rb', line 38 def clear_memory @content = nil end |
#exists? ⇒ Boolean
34 35 36 |
# File 'lib/fixture_kit/cache.rb', line 34 def exists? content || file_cache.exists? end |
#identifier ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fixture_kit/cache.rb', line 22 def identifier @identifier ||= begin raw_identifier = fixture.identifier if raw_identifier.is_a?(String) raw_identifier else normalized_scope = FixtureKit.runner.adapter.identifier_for(raw_identifier) File.join(ANONYMOUS_DIRECTORY, "#{normalized_scope}.#{definition_digest}") end end end |
#load ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fixture_kit/cache.rb', line 42 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
18 19 20 |
# File 'lib/fixture_kit/cache.rb', line 18 def path file_cache.path end |
#save ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fixture_kit/cache.rb', line 56 def save FixtureKit.runner.adapter.execute do |context| @content = MemoryCache.new( data: evaluate(FixtureKit.runner.coders, context), exposed: fixture.definition.exposed ) end file_cache.write(content) end |