Module: Familia::Base
Overview
Add a default update_expiration method for all classes that include
Familia::Base. Since expiration is a core feature, we can confidently
call horreum_instance.update_expiration
without defensive programming
even when expiration is not enabled for the horreum_instance class.
Class Attribute Summary collapse
-
.dump_method ⇒ Object
Returns the value of attribute dump_method.
-
.feature_definitions ⇒ Object
readonly
Returns the value of attribute feature_definitions.
-
.features_available ⇒ Object
readonly
Returns the value of attribute features_available.
-
.load_method ⇒ Object
Returns the value of attribute load_method.
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_id ⇒ Object
-
#to_s ⇒ String
Returns a string representation of the object.
-
#update_expiration(default_expiration: nil) ⇒ nil
Base implementation of update_expiration that maintains API compatibility with the :expiration feature’s implementation.
-
#uuid ⇒ Object
Class Attribute Details
.dump_method ⇒ Object
Returns the value of attribute dump_method.
34 35 36 |
# File 'lib/familia/base.rb', line 34 def dump_method @dump_method end |
.feature_definitions ⇒ Object (readonly)
Returns the value of attribute feature_definitions.
33 34 35 |
# File 'lib/familia/base.rb', line 33 def feature_definitions @feature_definitions end |
.features_available ⇒ Object (readonly)
Returns the value of attribute features_available.
33 34 35 |
# File 'lib/familia/base.rb', line 33 def features_available @features_available end |
.load_method ⇒ Object
Returns the value of attribute load_method.
34 35 36 |
# File 'lib/familia/base.rb', line 34 def load_method @load_method end |
Class Method Details
.add_feature(klass, feature_name, depends_on: []) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/familia/base.rb', line 36 def add_feature(klass, feature_name, depends_on: []) @features_available ||= {} Familia.trace :ADD_FEATURE, klass, feature_name, caller(1..1) if Familia.debug? # Create field definition object feature_def = FeatureDefinition.new( name: feature_name, depends_on: depends_on, ) # Track field definitions after defining field methods @feature_definitions ||= {} @feature_definitions[feature_name] = feature_def features_available[feature_name] = klass end |
Instance Method Details
#generate_id ⇒ Object
54 55 56 |
# File 'lib/familia/base.rb', line 54 def generate_id @identifier ||= Familia.generate_id # rubocop:disable Naming/MemoizedInstanceVariableName end |
#to_s ⇒ String
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.
28 29 30 |
# File 'lib/familia/base.rb', line 28 def to_s "#<#{self.class}:0x#{object_id.to_s(16)}>" end |
#update_expiration(default_expiration: nil) ⇒ nil
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.
122 123 124 125 126 127 128 |
# File 'lib/familia/features/expiration.rb', line 122 def update_expiration(default_expiration: nil) Familia.ld <<~LOG [update_expiration] Feature not enabled for #{self.class}. Key: #{dbkey} Arg: #{default_expiration} (caller: #{caller(1..1)}) LOG nil end |
#uuid ⇒ Object
58 59 60 |
# File 'lib/familia/base.rb', line 58 def uuid @uuid ||= SecureRandom.uuid end |