Module: Conflow::Redis::Model Private
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
-
.included(base) ⇒ Object
private
Extends base class with .field and .has_many methods.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
private
-
if other object is a Model as well, it compares keys - standard Ruby comparison otherwise.
-
-
#assign_attributes(**attributes) ⇒ Object
private
Convienience method for assigning multiple fields in model.
-
#destroy!(execute: true) ⇒ Object
private
Removes this and all related models.
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
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.
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 } = self.class.relations.map(&method(:collect_relation_keys)) (keys + ).flatten.tap do |key_list| command :del, [key_list] if execute && key_list.any? end end |