Module: Conflow::Redis::Model
Overview
Models adds .field method which allows to define fields easily.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Extends base class with .field and .has_many methods.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
-
if other object is a Model as well, it compares keys - standard Ruby comparison otherwise.
-
-
#destroy!(execute: true) ⇒ Object
Removes this and all related models.
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
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.
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 } = 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 |