Module: RedisRecord::Base

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

Class Method Summary collapse

Methods included from RedisConnection

connections, merge_and_resolve_default, procs_to_prepare

Methods included from Logger

proxy

Class Method Details

.included(klass) ⇒ Object


30
31
32
33
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
# File 'lib/redis_record/base.rb', line 30

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

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

    # RedisRecord 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,
    # RedisRecord 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