Module: Ruuuby::Attribute::Extendable::SyntaxCache
- Defined in:
- lib/ruuuby/module/attribute/extendable/syntax_cache.rb
Overview
provide functionality to automatically apply the Class-attribute: SyntaxCache
Instance Method Summary collapse
- #cache_fetch(cache_key) ⇒ *
-
#cache_generate(cache_key) ⇒ *
provide a default implementation.
- #cache_warmup(kclass) ⇒ Object
-
#cached_syntax ⇒ Hash
The current collection of cached keys n vals (belonging to the the
Class-instance, not instances of thatClass).
Instance Method Details
#cache_fetch(cache_key) ⇒ *
36 37 38 39 40 41 42 |
# File 'lib/ruuuby/module/attribute/extendable/syntax_cache.rb', line 36 def cache_fetch(cache_key) unless self.cached_syntax. |
#cache_generate(cache_key) ⇒ *
provide a default implementation
31 |
# File 'lib/ruuuby/module/attribute/extendable/syntax_cache.rb', line 31 def cache_generate(cache_key); ::Regexp.gen_closed_match(cache_key); end |
#cache_warmup(kclass) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruuuby/module/attribute/extendable/syntax_cache.rb', line 15 def cache_warmup(kclass) local_syntax = kclass::Syntax all_consts = local_syntax.constants all_consts.each do |c| unless c.start_with?('SQL_') kclass.define_singleton_method("syntax_#{c.⬇}") do kclass.cache_fetch(local_syntax.const_get(c)) end end end end |
#cached_syntax ⇒ Hash
Returns the current collection of cached keys n vals (belonging to the the Class-instance, not instances of that Class).
45 |
# File 'lib/ruuuby/module/attribute/extendable/syntax_cache.rb', line 45 def cached_syntax ; @cached_syntax ||= {} ; end |