Class: Sequel::Unicache::Configuration::ClassMethods::Utils
- Inherits:
-
Object
- Object
- Sequel::Unicache::Configuration::ClassMethods::Utils
- Defined in:
- lib/sequel/unicache/configuration.rb
Class Method Summary collapse
-
.fuzzy_search_for(keys, configs) ⇒ Object
fuzzy search will always search for enabled config.
- .initialize_unicache_for_class(model_class) ⇒ Object
- .initialize_unicache_for_key(model_class) ⇒ Object
- .normalize_key_for_unicache(keys) ⇒ Object
Class Method Details
.fuzzy_search_for(keys, configs) ⇒ Object
fuzzy search will always search for enabled config
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sequel/unicache/configuration.rb', line 95 def fuzzy_search_for keys, configs _, result = configs.detect do |cache_key, config| match = if cache_key.is_a? Array cache_key & keys == cache_key else keys.include? cache_key end match & config.cache && config.enabled end result end |
.initialize_unicache_for_class(model_class) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/sequel/unicache/configuration.rb', line 70 def initialize_unicache_for_class model_class model_class.instance_exec do plugin :dirty class_config = Unicache.config.to_h.merge model_class: model_class @unicache_class_configuration = Configuration.new class_config end Hook.install_hooks_for_unicache Transaction.install_hooks_for_unicache end |
.initialize_unicache_for_key(model_class) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/sequel/unicache/configuration.rb', line 80 def initialize_unicache_for_key model_class model_class.instance_exec do @unicache_key_configurations = {} if primary_key pk_config = @unicache_class_configuration.to_h.merge unicache_keys: model_class.primary_key @unicache_key_configurations[primary_key] = Configuration.new pk_config end end end |
.normalize_key_for_unicache(keys) ⇒ Object
90 91 92 |
# File 'lib/sequel/unicache/configuration.rb', line 90 def normalize_key_for_unicache keys keys.size == 1 ? keys.first.to_sym : keys.sort.map(&:to_sym) end |