Class: Cachetastic::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cachetastic/adapters/base.rb

Overview

class << self

Direct Known Subclasses

File, LocalMemory, Memcached

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Base

Returns a new instance of Base.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cachetastic/adapters/base.rb', line 20

def initialize(klass)
  self.klass = klass
  configatron.cachetastic.defaults.configatron_keys.each do |key|
    define_accessor(key)
    self.send("#{key}=", configatron.cachetastic.defaults.send(key))
  end
  klass.to_configatron(:cachetastic).configatron_keys.each do |key|
    define_accessor(key)
    self.send("#{key}=", klass.to_configatron(:cachetastic).send(key))
  end
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



18
19
20
# File 'lib/cachetastic/adapters/base.rb', line 18

def klass
  @klass
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/cachetastic/adapters/base.rb', line 46

def debug?
  return self.debug if self.respond_to?(:debug)
  return false
end

#marshal(value) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cachetastic/adapters/base.rb', line 51

def marshal(value)
  return nil if value.nil?
  case self.marshal_method.to_sym
  when :yaml
    return YAML.dump(value)
  when :ruby
    return Marshal.dump(value)
  else
    return value
  end
end

#transform_key(key) ⇒ Object

Allows an adapter to transform the key to a safe representation for it’s backend. For example, the key: ‘$*…123()%~q’ is not a key for the file system, so the Cachetastic::Adapters::File class should override this to make it safe for the file system.



38
39
40
# File 'lib/cachetastic/adapters/base.rb', line 38

def transform_key(key)
  key
end

#unmarshal(value) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cachetastic/adapters/base.rb', line 63

def unmarshal(value)
  return nil if value.nil?
  case self.marshal_method.to_sym
  when :yaml
    return YAML.load(value)
  when :ruby
    return Marshal.load(value)
  else
    return value
  end
end

#valid?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/cachetastic/adapters/base.rb', line 42

def valid?
  true
end