Module: Familia::Base

Included in:
DataType, Horreum
Defined in:
lib/familia/base.rb

Overview

A common module for Familia::DataType and Familia::Horreum to include.

This allows us to use a single comparison to check if a class is a Familia class. e.g.

klass.include?(Familia::Base) # => true
klass.ancestors.member?(Familia::Base) # => true

See Also:

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.dump_methodObject

Returns the value of attribute dump_method.



33
34
35
# File 'lib/familia/base.rb', line 33

def dump_method
  @dump_method
end

.featuresObject (readonly)

Returns the value of attribute features.



32
33
34
# File 'lib/familia/base.rb', line 32

def features
  @features
end

.load_methodObject

Returns the value of attribute load_method.



33
34
35
# File 'lib/familia/base.rb', line 33

def load_method
  @load_method
end

Class Method Details

.add_feature(klass, methname) ⇒ Object



35
36
37
38
39
40
# File 'lib/familia/base.rb', line 35

def add_feature(klass, methname)
  @features ||= {}
  Familia.ld "[#{self}] Adding feature #{klass} as #{methname.inspect}"

  features[methname] = klass
end

Instance Method Details

#generate_idObject



61
62
63
64
# File 'lib/familia/base.rb', line 61

def generate_id
  @identifier ||= Familia.generate_id
  @identifier
end

#to_sString

Returns a string representation of the object. Implementing classes are welcome to override this method to provide a more meaningful representation. Using this as a default via super is recommended.

Returns:

  • (String)

    A string representation of the object. Never nil.



27
28
29
# File 'lib/familia/base.rb', line 27

def to_s
  "#<#{self.class}:0x#{object_id.to_s(16)}>"
end

#update_expiration(default_expiration: nil) ⇒ nil

Note:

This is a no-op implementation. Classes that need expiration functionality should include the :expiration feature.

Base implementation of update_expiration that maintains API compatibility with the :expiration feature’s implementation.

This is a no-op implementation that gets overridden by features like :expiration. It accepts an optional default_expiration parameter to maintain interface compatibility with the overriding implementations.

Parameters:

  • default_expiration (Integer, nil) (defaults to: nil)

    Time To Live in seconds (ignored in base implementation)

Returns:

  • (nil)

    Always returns nil



56
57
58
59
# File 'lib/familia/base.rb', line 56

def update_expiration(default_expiration: nil)
  Familia.ld "[update_expiration] Feature not enabled for #{self.class}. Key: #{dbkey} (caller: #{caller(1..1)})"
  nil
end

#uuidObject



66
67
68
69
# File 'lib/familia/base.rb', line 66

def uuid
  @uuid ||= SecureRandom.uuid
  @uuid
end