Class: CachedColumn
- Inherits:
-
Object
- Object
- CachedColumn
- Defined in:
- lib/cached_column.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#column ⇒ Object
Returns the value of attribute column.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #before_save(record) ⇒ Object
- #computed_value(record) ⇒ Object
-
#initialize(column, options = {}, &block) ⇒ CachedColumn
constructor
A new instance of CachedColumn.
Constructor Details
#initialize(column, options = {}, &block) ⇒ CachedColumn
Returns a new instance of CachedColumn.
6 7 8 9 10 |
# File 'lib/cached_column.rb', line 6 def initialize(column, = {}, &block) @column = column = @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
4 5 6 |
# File 'lib/cached_column.rb', line 4 def block @block end |
#column ⇒ Object
Returns the value of attribute column.
4 5 6 |
# File 'lib/cached_column.rb', line 4 def column @column end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/cached_column.rb', line 4 def end |
Instance Method Details
#before_save(record) ⇒ Object
12 13 14 15 |
# File 'lib/cached_column.rb', line 12 def before_save(record) record.send("#{column}=", computed_value(record)) true end |
#computed_value(record) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cached_column.rb', line 17 def computed_value(record) if block record.instance_eval(&block) else record.send([:method] || column) end end |