Module: Familia::DataType::ClassMethods

Included in:
Familia::DataType
Defined in:
lib/familia/data_type/class_methods.rb

Overview

ClassMethods - Class-level DSL methods for defining DataType behavior

This module is extended into classes that inherit from Familia::DataType, providing class methods for type registration, configuration, and inheritance.

Key features:

  • Type registration system for creating DataType subclasses
  • Database and connection configuration
  • Inheritance hooks for propagating settings
  • Option validation and filtering

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#logical_database(val = nil) ⇒ Object



36
37
38
39
# File 'lib/familia/data_type/class_methods.rb', line 36

def logical_database(val = nil)
  @logical_database = val unless val.nil?
  @logical_database || parent&.logical_database
end

#parentObject

Returns the value of attribute parent.



17
18
19
# File 'lib/familia/data_type/class_methods.rb', line 17

def parent
  @parent
end

#prefixObject

Returns the value of attribute prefix.



17
18
19
# File 'lib/familia/data_type/class_methods.rb', line 17

def prefix
  @prefix
end

#suffixObject

Returns the value of attribute suffix.



17
18
19
# File 'lib/familia/data_type/class_methods.rb', line 17

def suffix
  @suffix
end

#uri(val = nil) ⇒ Object

Returns the value of attribute uri.



17
18
19
# File 'lib/familia/data_type/class_methods.rb', line 17

def uri
  @uri
end

Instance Method Details

#inherited(obj) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/familia/data_type/class_methods.rb', line 46

def inherited(obj)
  Familia.trace :DATATYPE, nil, "#{obj} is my kinda type" if Familia.debug?
  obj.logical_database = logical_database
  obj.default_expiration = default_expiration # method added via Features::Expiration
  obj.uri = uri
  super
end

#register(klass, methname) ⇒ Object

To be called inside every class that inherits DataType +methname+ is the term used for the class and instance methods that are created for the given +klass+ (e.g. set, list, etc)



23
24
25
26
27
# File 'lib/familia/data_type/class_methods.rb', line 23

def register(klass, methname)
  Familia.trace :REGISTER, nil, "[#{self}] Registering #{klass} as #{methname.inspect}" if Familia.debug?

  @registered_types[methname] = klass
end

#registered_type(methname) ⇒ Object

Get the registered type class from a given method name +methname+ is the method name used to register the class (e.g. :set, :list, etc) Returns the registered class or nil if not found



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

def registered_type(methname)
  @registered_types[methname]
end

#relations?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/familia/data_type/class_methods.rb', line 58

def relations?
  @has_related_fields ||= false
end

#valid_keys_only(opts) ⇒ Object



54
55
56
# File 'lib/familia/data_type/class_methods.rb', line 54

def valid_keys_only(opts)
  opts.slice(*DataType.valid_options)
end