Module: Erector::Caching

Defined in:
lib/erector/caching.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



38
39
40
# File 'lib/erector/caching.rb', line 38

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#_render(options = {}) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/erector/caching.rb', line 76

def _render(options = {})
  if should_cache?
    cache[self.class, assigns, options[:content_method_name]] ||= super
  else
    super
  end
end

#_render_via(parent, options = {}) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/erector/caching.rb', line 84

def _render_via(parent, options = {})
  if should_cache?
    parent.output << cache[self.class, assigns, options[:content_method_name]] ||= parent.capture { super }
    parent.output.widgets << self.class # todo: test!!!
  else
    super
  end
end

#cacheObject



68
69
70
# File 'lib/erector/caching.rb', line 68

def cache
  self.class.cache
end

#should_cache?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/erector/caching.rb', line 72

def should_cache?
  cache && block.nil? && self.class.cachable?
end