Class: Cash::Transactional
- Inherits:
-
Object
- Object
- Cash::Transactional
- Defined in:
- lib/cash/transactional.rb
Instance Attribute Summary collapse
-
#memcache ⇒ Object
readonly
Returns the value of attribute memcache.
Instance Method Summary collapse
-
#initialize(memcache, lock) ⇒ Transactional
constructor
A new instance of Transactional.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method) ⇒ Boolean
- #transaction ⇒ Object
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
25 26 27 |
# File 'lib/cash/transactional.rb', line 25 def method_missing(method, *args, &block) @cache.send(method, *args, &block) end |
Instance Attribute Details
#memcache ⇒ Object (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
29 30 31 |
# File 'lib/cash/transactional.rb', line 29 def respond_to?(method) @cache.respond_to?(method) end |
#transaction ⇒ Object
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 |