Module: Conflow::Redis::Identifier::ClassMethods Private
- Defined in:
- lib/conflow/redis/identifier.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
class methods for classes with identifier
Instance Attribute Summary collapse
-
#counter_key ⇒ String
private
Redis key holding counter with IDs of model.
-
#key_template ⇒ String
private
Template for building keys for fields using only the ID.
Instance Method Summary collapse
-
#generate_id ⇒ Integer
private
Next available ID.
-
#inherited(base) ⇒ Object
private
Copies counter_key and key_template to child classes.
Instance Attribute Details
#counter_key ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Redis key holding counter with IDs of model.
37 38 39 |
# File 'lib/conflow/redis/identifier.rb', line 37 def counter_key @counter_key ||= [*name.downcase.split("::"), :idcnt].join(":") end |
#key_template ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Template for building keys for fields using only the ID.
49 50 51 |
# File 'lib/conflow/redis/identifier.rb', line 49 def key_template @key_template ||= [*name.downcase.split("::"), "%<id>d"].join(":") end |
Instance Method Details
#generate_id ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns next available ID.
54 55 56 |
# File 'lib/conflow/redis/identifier.rb', line 54 def generate_id Conflow.redis.with { |conn| conn.incr(counter_key) } end |
#inherited(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Copies counter_key and key_template to child classes
23 24 25 26 27 |
# File 'lib/conflow/redis/identifier.rb', line 23 def inherited(base) base.instance_variable_set("@counter_key", counter_key) base.instance_variable_set("@key_template", key_template) super end |