Class: Cash::Transactional

Inherits:
Object
  • Object
show all
Defined in:
lib/cash/transactional.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(memcache, lock) ⇒ Transactional

Returns a new instance of Transactional.



5
6
7
8
# File 'lib/cash/transactional.rb', line 5

def initialize(memcache, lock)
  @memcache, @cache = [memcache, memcache]
  @lock = lock
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



31
32
33
# File 'lib/cash/transactional.rb', line 31

def method_missing(method, *args, &block)
  @cache.send(method, *args, &block)
end

Instance Attribute Details

#memcacheObject (readonly)

Returns the value of attribute memcache.



3
4
5
# File 'lib/cash/transactional.rb', line 3

def memcache
  @memcache
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/cash/transactional.rb', line 25

def respond_to?(method)
  @cache.respond_to?(method)
end

#transactionObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cash/transactional.rb', line 10

def transaction
  exception_was_raised = false
  begin_transaction
  result = yield
rescue Object => e
  exception_was_raised = true
  raise
ensure
  begin
    @cache.flush unless exception_was_raised
  ensure
    end_transaction
  end
end