Class Gibberish::Translation
In: lib/gibberish_db.rb
Parent: ActiveRecord::Base

Methods

Attributes

arguments  [RW] 

Public Class methods

[Source]

    # File lib/gibberish_db.rb, line 35
35:     def self.cache_key_for_language_and_key(lang,key)
36:       lang_id = lang.is_a?(Language) ? lang.id : lang
37:       ['find_by_language_id_and_key', lang_id, key.to_s[0..100]].join(':')
38:     end

[Source]

    # File lib/gibberish_db.rb, line 26
26:     def self.find_cached_by_language_and_key(lang,key)
27:       cache_key = cache_key_for_language_and_key(lang,key)
28:       cached = get_cache(cache_key) {nil}
29:       unless cached
30:         cached = Translation.find_by_language_id_and_key(lang.id,key.to_s)
31:         set_cache(cache_key, cached)
32:       end
33:       return cached
34:     end

[Source]

     # File lib/gibberish_db.rb, line 104
104:     def self.suppress_html_wrapper?
105:       @suppress_html
106:     end

Execute a block of code while suppressing the HTML wrapping that would otherwise take place when invoking .to_html

[Source]

     # File lib/gibberish_db.rb, line 94
 94:     def self.suppressing_html_wrapping(&block)
 95:       old_val = @suppress_html
 96:       @suppress_html = true
 97:       begin 
 98:         yield
 99:       ensure
100:         @suppress_html = old_val
101:       end
102:     end

Public Instance methods

[Source]

    # File lib/gibberish_db.rb, line 65
65:     def interpolate_with_hash(string, hash)
66:       hash.inject(string) do |target, (search, replace)|
67:         target.gsub("{#{search}}", replace)
68:       end 
69:     end

[Source]

    # File lib/gibberish_db.rb, line 71
71:     def interpolate_with_strings(string, strings)
72:       string.gsub(/\{\w+\}/) { strings.shift }
73:     end

[Source]

    # File lib/gibberish_db.rb, line 56
56:     def interpolated_value
57:       args = (arguments || []).dup 
58:       if args.last.is_a? Hash
59:         interpolate_with_hash(self.value, args.last)
60:       else
61:         interpolate_with_strings(self.value, args)
62:       end
63:     end

[Source]

    # File lib/gibberish_db.rb, line 39
39:     def invalidate_cache
40:       self.class.clear_cache(self.class.cache_key_for_language_and_key(language_id, key))
41:     end

[Source]

    # File lib/gibberish_db.rb, line 43
43:     def method_missing(name, *args, &block)
44:       return super if @attributes.include?(name.to_s)
45:       if self.value.respond_to?(name)
46:         if block_given?
47:           self.interpolated_value.send(name, *args, &block)
48:         else
49:           self.interpolated_value.send(name, *args)
50:         end
51:       else
52:         super
53:       end
54:     end

[Source]

    # File lib/gibberish_db.rb, line 83
83:     def to_html
84:       if Translation.suppress_html_wrapper?
85:         interpolated_value
86:       else
87:         tagname = (self.format == "block") ? "div" : "span"
88:         %Q{<#{tagname} class="translated key_#{key}" lang="#{language.name}">#{interpolated_value}</#{tagname}>}
89:       end
90:     end

[Source]

    # File lib/gibberish_db.rb, line 79
79:     def to_s
80:       interpolated_value
81:     end

[Source]

    # File lib/gibberish_db.rb, line 75
75:     def to_str
76:       interpolated_value
77:     end

[Validate]