Module: Conflow::Redis::Model Private

Included in:
Flow, Job, Promise
Defined in:
lib/conflow/redis/model.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.

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

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.

Extends base class with .field and .has_many methods



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

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

Instance Method Details

#==(other) ⇒ Boolean

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.

  • 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



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

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

#assign_attributes(**attributes) ⇒ 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.

Convienience method for assigning multiple fields in model



32
33
34
35
36
# File 'lib/conflow/redis/model.rb', line 32

def assign_attributes(**attributes)
  attributes.each do |attribute, value|
    send("#{attribute}=", value)
  end
end

#destroy!(execute: true) ⇒ 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.

Removes this and all related models.

Parameters:

  • execute (Boolean) (defaults to: true)

    if false, only returns keys that would be removed



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

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