Module: Conflow::Redis::Identifier::ClassMethods
- Defined in:
- lib/conflow/redis/identifier.rb
Overview
class methods for classes with identifier
Instance Attribute Summary collapse
-
#counter_key ⇒ String
Redis key holding counter with IDs of model.
-
#key_template ⇒ String
Template for building keys for fields using only the ID.
Instance Method Summary collapse
-
#generate_id ⇒ Integer
Next available ID.
-
#inherited(base) ⇒ Object
Copies counter_key and key_template to child classes.
Instance Attribute Details
#counter_key ⇒ String
Redis key holding counter with IDs of model.
33 34 35 |
# File 'lib/conflow/redis/identifier.rb', line 33 def counter_key @counter_key ||= [*name.downcase.split("::"), :idcnt].join(":") end |
#key_template ⇒ String
Template for building keys for fields using only the ID.
45 46 47 |
# File 'lib/conflow/redis/identifier.rb', line 45 def key_template @key_template ||= [*name.downcase.split("::"), "%<id>d"].join(":") end |
Instance Method Details
#generate_id ⇒ Integer
Returns next available ID.
50 51 52 |
# File 'lib/conflow/redis/identifier.rb', line 50 def generate_id Conflow.redis.with { |conn| conn.incr(counter_key) } end |
#inherited(base) ⇒ Object
Copies counter_key and key_template to child classes
19 20 21 22 23 |
# File 'lib/conflow/redis/identifier.rb', line 19 def inherited(base) base.instance_variable_set("@counter_key", counter_key) base.instance_variable_set("@key_template", key_template) super end |