Class: CacheStache::Keyspace

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_stache/keyspace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Keyspace

Returns a new instance of Keyspace.



9
10
11
12
13
# File 'lib/cache_stache/keyspace.rb', line 9

def initialize(name)
  @name = name
  @label = name.to_s.humanize
  @pattern = nil
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



7
8
9
# File 'lib/cache_stache/keyspace.rb', line 7

def label
  @label
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/cache_stache/keyspace.rb', line 7

def name
  @name
end

#patternObject

Returns the value of attribute pattern.



7
8
9
# File 'lib/cache_stache/keyspace.rb', line 7

def pattern
  @pattern
end

Instance Method Details

#match?(key) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/cache_stache/keyspace.rb', line 15

def match?(key)
  return false unless pattern
  pattern.match?(key.to_s)
rescue => e
  Rails.logger.error("CacheStache: Keyspace #{name} matcher error: #{e.message}")
  false
end

#validate!Object

Raises:



23
24
25
26
# File 'lib/cache_stache/keyspace.rb', line 23

def validate!
  raise Error, "Keyspace #{name} requires a match pattern (regex)" unless pattern
  raise Error, "Keyspace #{name} match pattern must be a Regexp" unless pattern.is_a?(Regexp)
end