Module: Conflow::Redis::Identifier

Included in:
Flow, Job
Defined in:
lib/conflow/redis/identifier.rb

Overview

Identifier changes logic of fields so that they can be found by an id. ID is a counter stored in redis under .counter_key Key is build with template stored in .key_template

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly)

ID of the model



56
57
58
# File 'lib/conflow/redis/identifier.rb', line 56

def id
  @id
end

Class Method Details

.included(base) ⇒ Object

Extends base class with ClassMethods



10
11
12
# File 'lib/conflow/redis/identifier.rb', line 10

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#initialize(id = self.class.generate_id) ⇒ Object

Overrides logic of Field#initialize, allowing creating objects with ID instead of full key

Parameters:

  • id (Integer) (defaults to: self.class.generate_id)

    ID of the model



60
61
62
63
# File 'lib/conflow/redis/identifier.rb', line 60

def initialize(id = self.class.generate_id)
  @id = id.to_i
  super(format(self.class.key_template, id: id))
end