Class: Redstruct::Types::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utils::Inspectable
Defined in:
lib/redstruct/types/base.rb

Overview

Base class for all objects a factory can produce

Direct Known Subclasses

Hls::Lock, Script, Struct

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Inspectable

#inspect, #to_s

Constructor Details

#initialize(key:, factory:) ⇒ Base

Returns a new instance of Base.



13
14
15
16
# File 'lib/redstruct/types/base.rb', line 13

def initialize(key:, factory:)
  @factory = factory
  @key = key
end

Instance Attribute Details

#keyString (readonly)

Returns The key used to identify the struct on redis.

Returns:

  • (String)

    The key used to identify the struct on redis



11
12
13
# File 'lib/redstruct/types/base.rb', line 11

def key
  @key
end

Instance Method Details

#inspectable_attributesObject

:nocov:



41
42
43
# File 'lib/redstruct/types/base.rb', line 41

def inspectable_attributes
  { key: @key, factory: @factory }
end

#to_hObject



29
30
31
# File 'lib/redstruct/types/base.rb', line 29

def to_h
  return { key: @key }
end

#withObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/redstruct/types/base.rb', line 18

def with
  self.connection.pool.with do |c|
    begin
      Thread.current[:__redstruct_connection] = c
      yield(c)
    ensure
      Thread.current[:__redstruct_connection] = nil
    end
  end
end