Module: CachedNames
- Defined in:
- lib/cached_names/base.rb,
lib/rails/cached_names.rb,
lib/cached_names/version.rb,
lib/cached_names/paranoid.rb
Defined Under Namespace
Modules: ParanoidMethods
Classes: Railtie
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.paranoid_loaded ⇒ Object
7
8
9
|
# File 'lib/cached_names/base.rb', line 7
def self.paranoid_loaded
@@paranoid_loaded
end
|
.paranoid_loaded=(value) ⇒ Object
4
5
6
|
# File 'lib/cached_names/base.rb', line 4
def self.paranoid_loaded=(value)
@@paranoid_loaded = value
end
|
Instance Method Details
#has_cached_names(name_method = "value", options = {}) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/cached_names/base.rb', line 11
def has_cached_names name_method = "value", options = {}
@cached_names_name_method = name_method
@cached_names_sort_field = options[:sorted_by] || @cached_names_name_method
@cached_names_group_method = options[:grouped_by]
@cached_names_cache_key_prefix = "cached_names_#{self}"
@cached_names_loaded = false
after_save { self.class.load_cached_names }
after_destroy { self.class.load_cached_names }
load_cached_names
load_paranoid_cached_names if CachedNames.paranoid_loaded
end
|
#load_cached_names ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/cached_names/base.rb', line 47
def load_cached_names
begin
@cached_names_instances = all(:order => @cached_names_sort_field)
load_names(@cached_names_instances)
load_grouped_names(@cached_names_instances) if @cached_names_group_method
@cached_names_loaded = true
rescue Exception => e
Rails.logger.error e.message
Rails.logger.error e.backtrace
@cached_names_loaded = false
end
end
|
#names ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/cached_names/base.rb', line 25
def names
load_cached_names unless @cached_names_loaded
begin
Rails.cache.read cache_key
rescue
load_cached_names
Rails.cache.read cache_key
end
end
|
#names_group(key) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cached_names/base.rb', line 36
def names_group key
load_cached_names unless @cached_names_loaded
begin
Rails.cache.read group_cache_key(key)
rescue
load_cached_names
Rails.cache.read group_cache_key(key)
end
end
|