Module: Sequel::Plugins::CachedRendering::ClassMethods
- Defined in:
- lib/cortex_reaver/support/cached_rendering.rb
Instance Method Summary collapse
-
#refresh_render_caches ⇒ Object
Refreshes all records with cached fields.
-
#render(field, params = {}) ⇒ Object
Assigns a field to cache.
- #render_fields ⇒ Object
Instance Method Details
#refresh_render_caches ⇒ Object
Refreshes all records with cached fields.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cortex_reaver/support/cached_rendering.rb', line 10 def refresh_render_caches # TODO: inefficient, but Model.each breaks Sequel in validation # "commands out of sync" all.each do |record| # Mark all caching columns as changed, so the before_save hook # processes them. record. = true render_fields.keys.each do |column| record.changed_columns << column end record.save end nil end |
#render(field, params = {}) ⇒ Object
Assigns a field to cache
render :body, :with => ‘wikify’, :to => ‘cached_body’
… calls #wikify on the value of self.body, and stores the result in self.cached_body. :to defaults to the field name with _cache appended. :with defaults to :render.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cortex_reaver/support/cached_rendering.rb', line 32 def render(field, params = {}) # Assign parameters params = { :to => (field.to_s + '_cache').to_sym, :with => :render }.merge!(params) # Store field render_fields[field] = OpenStruct.new(params) end |
#render_fields ⇒ Object
43 44 45 |
# File 'lib/cortex_reaver/support/cached_rendering.rb', line 43 def render_fields @render_fields ||= {} end |