Module: Sequel::Plugins::CachedRendering::InstanceMethods

Defined in:
lib/cortex_reaver/support/cached_rendering.rb

Instance Method Summary collapse

Instance Method Details

#before_saveObject

Before save, render all changed caching fields



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cortex_reaver/support/cached_rendering.rb', line 50

def before_save
  return false if super == false

  # Get changed fields to render
  if new?
    changed = columns.map { |c| c.to_sym }
  else
    changed = changed_columns.map { |c| c.to_sym }
  end
  fields = render_fields.select do |k, v|
    changed.include? k.to_sym
  end
  
  fields.each do |name, field|
    # Render and cache
    self[field.to] = self.send(field.with, self[name])
  end

  true
end

#render(value) ⇒ Object

Default renderer



72
73
74
# File 'lib/cortex_reaver/support/cached_rendering.rb', line 72

def render(value)
  value  
end

#render_fieldsObject



76
77
78
# File 'lib/cortex_reaver/support/cached_rendering.rb', line 76

def render_fields
  self.class.render_fields
end