Class ArkanisDevelopment::SimpleLocalization::CachedLangSectionProxy
In: lib/cached_lang_section_proxy.rb
Parent: LangSectionProxy

Extends the LangSectionProxy with simple caching functionality to avoid extensive combination work on every proxy method call.

Methods

Public Class methods

Calls super to do the work and initializes +@cached_receivers+ with an empty hash (empty cache). +@cached_receivers+ will hold a cached version of the receiver for each language file (keys of the hash).

[Source]

    # File lib/cached_lang_section_proxy.rb, line 13
13:       def initialize(*args)
14:         super
15:         @cached_receivers = {}
16:       end

Public Instance methods

Looks in the +@cached_receivers+ hash for a cached receiver for the current language. If found the cached on will be used. Otherwise +self.receiver+ will be called to get the receiver (and all the combination work is done) and the result is cached in the +@cached_receivers+ hash.

If currently no language is loaded (@lang_class.current_language returns nil) +self.receiver+ is called without being cached. This is because if no language file is loaded +self.receiver+ will probably return a fallback value.

[Source]

    # File lib/cached_lang_section_proxy.rb, line 28
28:       def method_missing(name, *args, &block)
29:         lang = @lang_class.current_language
30:         target_receiver = if lang
31:           @cached_receivers[lang] || begin
32:             @cached_receivers[lang] = self.receiver
33:           end
34:         else
35:           self.receiver
36:         end
37:         target_receiver.send name, *args, &block
38:       end

[Validate]