Class: Cash::Mock::CacheEntry
- Inherits:
-
Object
- Object
- Cash::Mock::CacheEntry
- Defined in:
- lib/cash/mock.rb
Instance Attribute Summary (collapse)
-
- (Object) value
readonly
Returns the value of attribute value.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) decrement(amount = 1)
- - (Boolean) expired?
- - (Object) increment(amount = 1)
-
- (CacheEntry) initialize(value, raw, ttl)
constructor
A new instance of CacheEntry.
- - (Object) to_i
- - (Object) unmarshal
Constructor Details
- (CacheEntry) initialize(value, raw, ttl)
A new instance of CacheEntry
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cash/mock.rb', line 16 def initialize(value, raw, ttl) if raw @value = value.to_s else @value = Marshal.dump(value) end if ttl.nil? || ttl.zero? @ttl = self.class.default_ttl else @ttl = ttl end @expires_at = self.class.now + @ttl end |
Instance Attribute Details
- (Object) value (readonly)
Returns the value of attribute value
6 7 8 |
# File 'lib/cash/mock.rb', line 6 def value @value end |
Class Method Details
+ (Object) default_ttl
8 9 10 |
# File 'lib/cash/mock.rb', line 8 def self.default_ttl 1_000_000 end |
+ (Object) now
12 13 14 |
# File 'lib/cash/mock.rb', line 12 def self.now Time.now end |
Instance Method Details
- (Object) decrement(amount = 1)
41 42 43 |
# File 'lib/cash/mock.rb', line 41 def decrement(amount = 1) @value = (@value.to_i - amount).to_s end |
- (Boolean) expired?
33 34 35 |
# File 'lib/cash/mock.rb', line 33 def expired? self.class.now > @expires_at end |
- (Object) increment(amount = 1)
37 38 39 |
# File 'lib/cash/mock.rb', line 37 def increment(amount = 1) @value = (@value.to_i + amount).to_s end |
- (Object) to_i
49 50 51 |
# File 'lib/cash/mock.rb', line 49 def to_i @value.to_i end |
- (Object) unmarshal
45 46 47 |
# File 'lib/cash/mock.rb', line 45 def unmarshal Marshal.load(@value) end |