Class: ActionHandle::Base
- Inherits:
-
Object
- Object
- ActionHandle::Base
- Defined in:
- lib/action_handle/base.rb
Constant Summary collapse
- BUILTIN_ADAPTERS =
{ redis: Adapters::RedisPool, cache: Adapters::CacheStore }.freeze
Instance Attribute Summary collapse
-
#instance_value ⇒ Object
readonly
Returns the value of attribute instance_value.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
- .claim(*args, &block) ⇒ Object
- .create(*args, &block) ⇒ Object
- .expire(*args, &block) ⇒ Object
- .prefix(string = nil) ⇒ Object
- .renew(*args, &block) ⇒ Object
- .ttl(amount = nil) ⇒ Object
- .value(*args, &block) ⇒ Object
Instance Method Summary collapse
- #adapter ⇒ Object
- #claim ⇒ Object
- #create ⇒ Object
- #current? ⇒ Boolean
- #expire ⇒ Object
- #handle_key ⇒ Object
-
#initialize(key, instance_value = nil) ⇒ Base
constructor
A new instance of Base.
- #renew ⇒ Object
- #taken? ⇒ Boolean
- #ttl ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(key, instance_value = nil) ⇒ Base
Returns a new instance of Base.
45 46 47 48 |
# File 'lib/action_handle/base.rb', line 45 def initialize(key, instance_value = nil) @key = key @instance_value = instance_value end |
Instance Attribute Details
#instance_value ⇒ Object (readonly)
Returns the value of attribute instance_value.
43 44 45 |
# File 'lib/action_handle/base.rb', line 43 def instance_value @instance_value end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
43 44 45 |
# File 'lib/action_handle/base.rb', line 43 def key @key end |
Class Method Details
.claim(*args, &block) ⇒ Object
34 35 36 |
# File 'lib/action_handle/base.rb', line 34 def claim(*args, &block) new(*args, &block).claim end |
.create(*args, &block) ⇒ Object
22 23 24 |
# File 'lib/action_handle/base.rb', line 22 def create(*args, &block) new(*args, &block).create end |
.expire(*args, &block) ⇒ Object
26 27 28 |
# File 'lib/action_handle/base.rb', line 26 def expire(*args, &block) new(*args, &block).expire end |
.prefix(string = nil) ⇒ Object
11 12 13 14 |
# File 'lib/action_handle/base.rb', line 11 def prefix(string = nil) @prefix = string if string @prefix end |
.renew(*args, &block) ⇒ Object
30 31 32 |
# File 'lib/action_handle/base.rb', line 30 def renew(*args, &block) new(*args, &block).renew end |
.ttl(amount = nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/action_handle/base.rb', line 16 def ttl(amount = nil) @ttl = amount if amount @ttl ||= 100 @ttl end |
.value(*args, &block) ⇒ Object
38 39 40 |
# File 'lib/action_handle/base.rb', line 38 def value(*args, &block) new(*args, &block).value end |
Instance Method Details
#adapter ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/action_handle/base.rb', line 86 def adapter @adapter ||= case Configuration.adapter when Symbol, String klass = BUILTIN_ADAPTERS[Configuration.adapter.to_sym] klass&.new(*Configuration.redis_pool) else Configuration.adapter end end |
#claim ⇒ Object
70 71 72 |
# File 'lib/action_handle/base.rb', line 70 def claim adapter.claim(handle_key, instance_value, ttl) end |
#create ⇒ Object
50 51 52 |
# File 'lib/action_handle/base.rb', line 50 def create adapter.create(handle_key, instance_value, ttl) end |
#current? ⇒ Boolean
62 63 64 |
# File 'lib/action_handle/base.rb', line 62 def current? adapter.current?(handle_key, instance_value) end |
#expire ⇒ Object
74 75 76 |
# File 'lib/action_handle/base.rb', line 74 def expire adapter.expire(handle_key) end |
#handle_key ⇒ Object
82 83 84 |
# File 'lib/action_handle/base.rb', line 82 def handle_key ['AH', self.class.prefix, key].join('/') end |
#renew ⇒ Object
54 55 56 |
# File 'lib/action_handle/base.rb', line 54 def renew adapter.renew(handle_key, instance_value, ttl) end |
#taken? ⇒ Boolean
58 59 60 |
# File 'lib/action_handle/base.rb', line 58 def taken? adapter.taken?(handle_key) end |
#ttl ⇒ Object
78 79 80 |
# File 'lib/action_handle/base.rb', line 78 def ttl self.class.ttl end |
#value ⇒ Object
66 67 68 |
# File 'lib/action_handle/base.rb', line 66 def value adapter.value(handle_key) end |