Class: RSpecRailsCaching::TestStore

Inherits:
ActiveSupport::Cache::Store
  • Object
show all
Defined in:
lib/rspec-rails-caching/test_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ TestStore

Returns a new instance of TestStore.



14
15
16
17
18
19
20
21
22
# File 'lib/rspec-rails-caching/test_store.rb', line 14

def initialize(options = nil)
  @options = options ? options.dup : {do_read_cache: false}
  @data = {}
  @cached = []
  @expired = []
  @expiration_patterns = []
  @cached_pages = []
  @expired_pages = []
end

Instance Attribute Details

#cachedObject (readonly)

Returns the value of attribute cached.



4
5
6
# File 'lib/rspec-rails-caching/test_store.rb', line 4

def cached
  @cached
end

#cached_pagesObject (readonly)

Returns the value of attribute cached_pages.



9
10
11
# File 'lib/rspec-rails-caching/test_store.rb', line 9

def cached_pages
  @cached_pages
end

#contextObject

Returns the value of attribute context.



12
13
14
# File 'lib/rspec-rails-caching/test_store.rb', line 12

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/rspec-rails-caching/test_store.rb', line 7

def data
  @data
end

#expiration_patternsObject (readonly)

Returns the value of attribute expiration_patterns.



6
7
8
# File 'lib/rspec-rails-caching/test_store.rb', line 6

def expiration_patterns
  @expiration_patterns
end

#expiredObject (readonly)

Returns the value of attribute expired.



5
6
7
# File 'lib/rspec-rails-caching/test_store.rb', line 5

def expired
  @expired
end

#expired_pagesObject (readonly)

Returns the value of attribute expired_pages.



10
11
12
# File 'lib/rspec-rails-caching/test_store.rb', line 10

def expired_pages
  @expired_pages
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/rspec-rails-caching/test_store.rb', line 8

def options
  @options
end

Instance Method Details

#cached?(name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rspec-rails-caching/test_store.rb', line 48

def cached?(name)
  @cached.include?(name)
end

#delete_entry(name, options = {}) ⇒ Object



40
41
42
# File 'lib/rspec-rails-caching/test_store.rb', line 40

def delete_entry(name, options = {})
  @expired << name
end

#delete_matched(matcher, options = {}) ⇒ Object



44
45
46
# File 'lib/rspec-rails-caching/test_store.rb', line 44

def delete_matched(matcher, options = {})
  @expiration_patterns << matcher
end

#expired?(name) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/rspec-rails-caching/test_store.rb', line 52

def expired?(name)
  @expired.include?(name) || @expiration_patterns.detect { |matcher| name =~ matcher }
end

#page_cached?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rspec-rails-caching/test_store.rb', line 56

def page_cached?(options = {})
  @cached_pages.include?(test_cache_url(options))
end

#page_expired?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/rspec-rails-caching/test_store.rb', line 60

def page_expired?(options = {})
  @expired_pages.include?(test_cache_url(options))
end

#read_entry(name, options = {}) ⇒ Object



31
32
33
# File 'lib/rspec-rails-caching/test_store.rb', line 31

def read_entry(name, options = {})
  options[:do_read_cache] ? @data[name] : nil
end

#resetObject



24
25
26
27
28
29
# File 'lib/rspec-rails-caching/test_store.rb', line 24

def reset
  @data.clear
  @cached.clear
  @expired.clear
  @expiration_patterns.clear
end

#write_entry(name, value, options = {}) ⇒ Object



35
36
37
38
# File 'lib/rspec-rails-caching/test_store.rb', line 35

def write_entry(name, value, options = {})
  @data[name] = value if options[:do_read_cache]
  @cached << name
end