class StrategyStore::Strategy::AccessorHash
Attributes
columns[RW]
source[RW]
Public Class Methods
new(source, columns)
click to toggle source
TODO - rpc : Set the columns when registering the strategy with const : class << self
attr_reader :columns def create(columns) Class.new(self) do @columns = columns; end end
end def columns; self.class.columns; end
def initialize(source)
@source = source @source.slice!(*default_attributes.keys) @source.reverse_merge!(default_attributes)
end
# File lib/strategy_store/strategy/accessor_hash.rb, line 23 def initialize(source, columns) @source = source @columns = columns @source.slice!(*default_attributes.keys) @source.reverse_merge!(default_attributes) end
Public Instance Methods
[](key)
click to toggle source
# File lib/strategy_store/strategy/accessor_hash.rb, line 31 def [](key); cast(key, source[key]); end
[]=(key, value)
click to toggle source
# File lib/strategy_store/strategy/accessor_hash.rb, line 30 def []=(key, value); source[key] = cast(key, value); end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/strategy_store/strategy/accessor_hash.rb, line 33 def method_missing(method_name, *args, &block) if source.respond_to?(method_name, false) # FIXME : include_private method? source.send(method_name, *args, &block) else super end end
Private Instance Methods
cast(key, value)
click to toggle source
# File lib/strategy_store/strategy/accessor_hash.rb, line 42 def cast(key, value); columns[key].cast(value); end
default_attributes()
click to toggle source
# File lib/strategy_store/strategy/accessor_hash.rb, line 44 def default_attributes columns.values.inject({}) do |acc, column| acc[column.name] = column.default acc end end