Module: Redcord::Base

Extended by:
T::Helpers, T::Sig
Includes:
Configurations, Logger, RedisConnection, Tracer
Defined in:
lib/redcord/base.rb

Constant Summary

Constants included from RedisConnection

RedisConnection::RedcordClientType

Class Method Summary collapse

Methods included from RedisConnection

connections, merge_and_resolve_default, procs_to_prepare

Methods included from Logger

proxy

Class Method Details

.descendantsObject



65
66
67
68
69
70
71
72
# File 'lib/redcord/base.rb', line 65

def self.descendants
  descendants = []
  # TODO: Use T::Struct instead of Class
  ObjectSpace.each_object(Class) do |klass|
    descendants << klass if klass < self
  end
  descendants
end

.included(klass) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/redcord/base.rb', line 34

def self.included(klass)
  # Redcord uses `T::Struct` to validate the attribute types. The
  # Redcord models need to inherit `T::Struct` and include
  # `Redcord::Base`, for example:
  #
  #   class MyRedisModel < T::Struct
  #     include Redcord::Base
  #
  #     attribute :my_redis_value, Integer
  #   end
  #
  # See more examples in spec/lib/redcord_spec.rb.

  klass.class_eval do
    # Redcord Model level methods
    include Redcord::Serializer
    include Redcord::Actions
    include Redcord::Attribute
    include Redcord::RedisConnection

    # Redcord stores the serialized model as a hash on Redis. When
    # reading a model from Redis, the hash fields are deserialized and
    # coerced to the specified attribute types. Like ActiveRecord,
    # Redcord manages the created_at and updated_at fields behind the
    # scene.
    prop :created_at, T.nilable(Time)
    prop :updated_at, T.nilable(Time)
  end
end