class Stacks::ReportCache
Attributes
cache_condition[RW]
report_name[RW]
ttl[RW]
values[RW]
Public Class Methods
get_report(report_name)
click to toggle source
# File lib/stacks/report_cache.rb, line 11 def self.get_report(report_name) raise "Invalid report name" unless @reports.keys.include?(report_name) reports[report_name] end
new(report_name, ttl)
click to toggle source
# File lib/stacks/report_cache.rb, line 16 def initialize(report_name, ttl) @report_name = report_name @values = {} @ttl = ttl end
report(report_name, ttl, &block)
click to toggle source
# File lib/stacks/report_cache.rb, line 57 def self.report(report_name, ttl, &block) report = new(report_name, ttl) report.instance_eval(&block) reports[report_name] = report report end
reports()
click to toggle source
# File lib/stacks/report_cache.rb, line 7 def self.reports @reports ||= {} end
Public Instance Methods
backend()
click to toggle source
# File lib/stacks/report_cache.rb, line 70 def backend return @backend if @backend backend = Stacks::Backends::NamespacedBackend.new backend.namespace = @report_name @backend ||= backend end
fill_cache()
click to toggle source
# File lib/stacks/report_cache.rb, line 48 def fill_cache if cache_condition return unless cache_condition.call end @values.each { |value_name, item| backend.fill(item, @ttl) } backend.fill(Stacks::Items::Timestamp.new, @ttl) end
get_item(item)
click to toggle source
# File lib/stacks/report_cache.rb, line 30 def get_item(item) if cache_condition Stacks.deactivate = true unless cache_condition.call end value = self.class.get_value(item, backend, @ttl) Stacks.deactivate = false value end
get_value(value_name)
click to toggle source
# File lib/stacks/report_cache.rb, line 40 def get_value(value_name) get_item(@values[value_name]) end
register_instance_variables(instance)
click to toggle source
# File lib/stacks/report_cache.rb, line 64 def register_instance_variables(instance) values.each do |value_name, item| instance.instance_variable_set("@#{value_name}".to_sym, get_value(value_name)) end end
set_cache_condition(&block)
click to toggle source
# File lib/stacks/report_cache.rb, line 22 def set_cache_condition(&block) @cache_condition = block end
timestamp()
click to toggle source
# File lib/stacks/report_cache.rb, line 44 def timestamp get_item(Stacks::Items::Timestamp.new) end
value(value_name, &block)
click to toggle source
# File lib/stacks/report_cache.rb, line 26 def value(value_name, &block) @values[value_name] = Stacks::Items::Proc.new(value_name, block) end