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)


50
51
52
# File 'lib/rspec-rails-caching/test_store.rb', line 50

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

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



42
43
44
# File 'lib/rspec-rails-caching/test_store.rb', line 42

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

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



46
47
48
# File 'lib/rspec-rails-caching/test_store.rb', line 46

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

#expired?(name) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rspec-rails-caching/test_store.rb', line 54

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

#page_cached?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/rspec-rails-caching/test_store.rb', line 58

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

#page_expired?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/rspec-rails-caching/test_store.rb', line 62

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

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



33
34
35
# File 'lib/rspec-rails-caching/test_store.rb', line 33

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

#resetObject



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

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

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



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

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