Module: Golden::Setting::Cache::ClassMethods
- Defined in:
- lib/golden/setting/cache.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #delete_cache(name) ⇒ Object
- #fetch_cache(name) ⇒ Object
- #is_true?(name) ⇒ Boolean
- #rewrite_cache(name, value) ⇒ Object
Instance Method Details
#[](name) ⇒ Object
28 29 30 31 |
# File 'lib/golden/setting/cache.rb', line 28 def [] name obj = fetch_cache(name) { super(name) } obj || defaults[name.to_sym] end |
#[]=(name, value) ⇒ Object
33 34 35 36 37 |
# File 'lib/golden/setting/cache.rb', line 33 def []= name, value if self[name] != value super name, value end end |
#delete_cache(name) ⇒ Object
24 25 26 |
# File 'lib/golden/setting/cache.rb', line 24 def delete_cache name ::Rails.cache.delete "setting:#{name}" end |
#fetch_cache(name) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/golden/setting/cache.rb', line 12 def fetch_cache name if block_given? ::Rails.cache.fetch("setting:#{name}") { yield } else ::Rails.cache.fetch "setting:#{name}" end end |
#is_true?(name) ⇒ Boolean
39 40 41 |
# File 'lib/golden/setting/cache.rb', line 39 def is_true? name fetch_cache("#{name}?") { super(name) } end |
#rewrite_cache(name, value) ⇒ Object
20 21 22 |
# File 'lib/golden/setting/cache.rb', line 20 def rewrite_cache name, value ::Rails.cache.write "setting:#{name}", value end |