Module: ConcernsOnRails::Models::Storable::ClassMethods
- Includes:
- Support::ColumnGuard
- Defined in:
- lib/concerns_on_rails/models/storable.rb
Instance Method Summary collapse
-
#storable_by(column, keys = {}, prefix: nil, suffix: nil, **kw_keys) ⇒ Object
Declare typed accessors over ‘column`.
-
#storable_native_hash_column?(column) ⇒ Boolean
Lazily decide — once per class/column, at first write when a DB connection exists — whether the column’s attribute type stores a Hash natively (a :json column, or a host-app ‘serialize`d column) so we can hand it the Hash; everything else gets a generated JSON String.
Methods included from Support::ColumnGuard
Instance Method Details
#storable_by(column, keys = {}, prefix: nil, suffix: nil, **kw_keys) ⇒ Object
Declare typed accessors over ‘column`. Key specs may arrive as the positional `keys` Hash or as trailing keyword arguments (they are merged); the positional form is the escape hatch for keys literally named `prefix`/`suffix`. See the module docs.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/concerns_on_rails/models/storable.rb', line 103 def storable_by(column, keys = {}, prefix: nil, suffix: nil, **kw_keys) column = column.to_sym ensure_columns!(LABEL, column) prepared = storable_merge_key_specs(keys, kw_keys).map do |key, raw_spec| key = key.to_sym [key, storable_normalize_spec(key, raw_spec, prefix, suffix)] end storable_install_keys(column, prepared) end |
#storable_native_hash_column?(column) ⇒ Boolean
Lazily decide — once per class/column, at first write when a DB connection exists — whether the column’s attribute type stores a Hash natively (a :json column, or a host-app ‘serialize`d column) so we can hand it the Hash; everything else gets a generated JSON String.
119 120 121 122 123 124 125 |
# File 'lib/concerns_on_rails/models/storable.rb', line 119 def storable_native_hash_column?(column) cache = (@storable_native_hash_cache ||= {}) name = column.to_sym return cache[name] if cache.key?(name) cache[name] = storable_detect_native_hash(column) end |