Class: Familia::DataType Abstract
- Inherits:
-
Object
- Object
- Familia::DataType
- Extended by:
- ClassMethods, Features
- Includes:
- Base, Connection, DatabaseCommands, Serialization, Settings
- Defined in:
- lib/familia/data_type.rb,
lib/familia/data_type/settings.rb,
lib/familia/data_type/connection.rb,
lib/familia/data_type/class_methods.rb,
lib/familia/data_type/serialization.rb,
lib/familia/data_type/database_commands.rb
Overview
Subclass and implement Database data type specific methods
DataType - Base class for Database data type wrappers
This class provides common functionality for various Database data types such as String, JsonStringKey, List, UnsortedSet, SortedSet, and HashKey.
Direct Known Subclasses
HashKey, JsonStringKey, ListKey, SortedSet, StringKey, UnsortedSet
Defined Under Namespace
Modules: ClassMethods, Connection, DatabaseCommands, Serialization, Settings
Class Attribute Summary collapse
-
.has_related_fields ⇒ Object
readonly
Returns the value of attribute has_related_fields.
-
.registered_types ⇒ Object
readonly
Returns the value of attribute registered_types.
-
.valid_options ⇒ Object
readonly
Returns the value of attribute valid_options.
Instance Attribute Summary collapse
-
#features_enabled ⇒ Object
included
from Features
readonly
Returns the value of attribute features_enabled.
- #logical_database(val = nil) ⇒ Object included from ClassMethods
-
#parent ⇒ Object
included
from ClassMethods
Returns the value of attribute parent.
-
#prefix ⇒ Object
included
from ClassMethods
Returns the value of attribute prefix.
-
#suffix ⇒ Object
included
from ClassMethods
Returns the value of attribute suffix.
-
#uri(val = nil) ⇒ Object
included
from ClassMethods
Returns the value of attribute uri.
Attributes included from Settings
#current_key_version, #default_expiration, #delim, #encryption_keys, #encryption_personalization, #logical_database, #prefix, #schema_path, #schema_validator, #schemas, #suffix, #transaction_mode
Class Method Summary collapse
-
.feature(feature_name = nil, **options) ⇒ Array?
extended
from Features
Enables a feature for the current class with optional configuration.
- .inherited(obj) ⇒ Object extended from ClassMethods
-
.register(klass, methname) ⇒ Object
extended
from ClassMethods
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).
-
.registered_type(methname) ⇒ Object
extended
from ClassMethods
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.
- .relations? ⇒ Boolean extended from ClassMethods
- .valid_keys_only(opts) ⇒ Object extended from ClassMethods
Instance Method Summary collapse
-
#initialize(keystring, opts = {}) ⇒ DataType
constructor
+keystring+: If parent is set, this will be used as the suffix for dbkey.
Methods included from Features::Autoloader
autoload_files, included, normalize_to_config_name
Methods included from Serialization
#deserialize_value, #deserialize_values, #deserialize_values_with_nil, #serialize_value
Methods included from DatabaseCommands
#current_expiration, #delete!, #echo, #exists?, #expire, #expireat, #move, #persist, #rename, #renamenx, #type
Methods included from Connection
#dbclient, #dbkey, #direct_access, #uri
Methods included from Connection::Behavior
#connect, #create_dbclient, #multi, #normalize_uri, #pipeline, #pipelined, #transaction, #uri=, #url, #url=
Methods included from Settings
#configure, #default_suffix, #pipelined_mode, #pipelined_mode=
Methods included from Base
add_feature, #as_json, #expired?, #expires?, find_feature, #generate_id, #to_json, #to_s, #ttl, #update_expiration, #uuid
Constructor Details
#initialize(keystring, opts = {}) ⇒ DataType
+keystring+: If parent is set, this will be used as the suffix for dbkey. Otherwise this becomes the value of the key. If this is an Array, the elements will be joined.
Options:
:class => A class that responds to from_json. This will be used when loading data from the database to unmarshal the class. JSON serialization is used for all data storage.
:parent => The Familia object that this datatype object belongs to. This can be a class that includes Familia or an instance.
:default_expiration => the time to live in seconds. When not nil, this will set the default expiration for this dbkey whenever #save is called. You can also call it explicitly via #update_expiration.
:default => the default value (String-only)
:dbkey => a hardcoded key to use instead of the deriving the from the name and parent (e.g. a derived key: customer:custid:secret_counter).
:suffix => the suffix to use for the key (e.g. 'scores' in customer:custid:scores). :prefix => the prefix to use for the key (e.g. 'customer' in customer:custid:scores).
Connection precendence: uses the database connection of the parent or the value of opts[:dbclient] or Familia.dbclient (in that order).
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/familia/data_type.rb', line 65 def initialize(keystring, opts = {}) @keystring = keystring @keystring = @keystring.join(Familia.delim) if @keystring.is_a?(Array) # Remove all keys from the opts that are not in the allowed list @opts = DataType.valid_keys_only(opts || {}) # Apply the options to instance method setters of the same name @opts.each do |k, v| send(:"#{k}=", v) if respond_to? :"#{k}=" end init if respond_to? :init end |
Class Attribute Details
.has_related_fields ⇒ Object (readonly)
Returns the value of attribute has_related_fields.
35 36 37 |
# File 'lib/familia/data_type.rb', line 35 def @has_related_fields end |
.registered_types ⇒ Object (readonly)
Returns the value of attribute registered_types.
35 36 37 |
# File 'lib/familia/data_type.rb', line 35 def registered_types @registered_types end |
.valid_options ⇒ Object (readonly)
Returns the value of attribute valid_options.
35 36 37 |
# File 'lib/familia/data_type.rb', line 35 def @valid_options end |
Instance Attribute Details
#features_enabled ⇒ Object (readonly) Originally defined in module Features
Returns the value of attribute features_enabled.
#logical_database(val = nil) ⇒ Object Originally defined in module ClassMethods
#parent ⇒ Object Originally defined in module ClassMethods
Returns the value of attribute parent.
#prefix ⇒ Object Originally defined in module ClassMethods
Returns the value of attribute prefix.
#suffix ⇒ Object Originally defined in module ClassMethods
Returns the value of attribute suffix.
#uri(val = nil) ⇒ Object Originally defined in module ClassMethods
Returns the value of attribute uri.
Class Method Details
.feature(feature_name = nil, **options) ⇒ Array? Originally defined in module Features
Enables a feature for the current class with optional configuration.
Features are modular capabilities that can be mixed into Familia::Horreum classes. Each feature can be configured with options that are stored per-class, ensuring complete isolation between different models.
.inherited(obj) ⇒ Object Originally defined in module ClassMethods
.register(klass, methname) ⇒ Object Originally defined in module ClassMethods
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)
.registered_type(methname) ⇒ Object Originally defined in module ClassMethods
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