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

Instance Method Details

#cache_fetch(cache_key) ⇒ *

Parameters:

Returns:

  • (*)


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

Returns:

  • (*)


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_syntaxHash

Returns the current collection of cached keys n vals (belonging to the the Class-instance, not instances of that Class).

Returns:

  • (Hash)

    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