Module: Conflow::Redis::Model

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

Overview

Models adds .field method which allows to define fields easily.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extends base class with .field and .has_many methods



8
9
10
# File 'lib/conflow/redis/model.rb', line 8

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

Instance Method Details

#==(other) ⇒ Boolean

  • if other object is a Conflow::Redis::Model as well, it compares keys

  • standard Ruby comparison otherwise

Returns:

  • (Boolean)

    true if other is the same model, false otherwise



15
16
17
# File 'lib/conflow/redis/model.rb', line 15

def ==(other)
  other.is_a?(Model) ? key == other.key : super
end

#destroy!(execute: true) ⇒ Object

Removes this and all related models.

Parameters:

  • execute (Boolean) (defaults to: true)

    if false, only returns keys that would be removed



21
22
23
24
25
26
27
28
# File 'lib/conflow/redis/model.rb', line 21

def destroy!(execute: true)
  keys = self.class.fields.map { |name| send(name).key }
  related_keys = self.class.relations.map(&method(:collect_relation_keys))

  (keys + related_keys).flatten.tap do |key_list|
    command :del, [key_list] if execute && key_list.any?
  end
end