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

Instance Method Summary collapse

Instance Attribute Details

#counter_keyString

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.

Examples:

default key

class My::Super::Class < Conflow::Redis::Field
  include Conflow::Redis::Identifier
end

My::Super::Class.counter_key #=> "my:super:class:idcnt"

Returns:

  • (String)

    Redis key



37
38
39
# File 'lib/conflow/redis/identifier.rb', line 37

def counter_key
  @counter_key ||= [*name.downcase.split("::"), :idcnt].join(":")
end

#key_templateString

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.

Examples:

default key

class My::Super::Class < Conflow::Redis::Field
  include Conflow::Redis::Identifier
end

My::Super::Class.key_template #=> "my:super:class:%<id>d"

Returns:

  • (String)

    Template for building redis keys



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_idInteger

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.

Returns:

  • (Integer)

    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