Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
ProxyField ========== ProxyField provied the ability to proxy an ActiveRecord column or columns through another object. Example ======= You store time duration in seconds in ActiveRecord column called "duration". Lets say your model is called WaitingRoom. If you wanted to get the hours from an instance of the model you would have w = WaitingRoom.find(CONDITIONS) w.duration / 60 / 60 # to get the hours ProxyField would allow you to easily override the default return value of the call to duration with another object. It will create an instance of your wrapper object with the columns value as its constructor parameter. class DurationField def initialize(seconds) @seconds = seconds end def to_hours @seconds / 60 / 60 end # more methods on the proxy here # to_seconds, to_minutes, to_days # to_weeks, to_years, etc... end class WaitingRoom < ActiveRecord::Base proxy_field :duration, :as => DurationField # Also valid # proxy_field [:col1, :col2], :as => ProxyObj end Now I can say: w = WaitingRoom.find(CONDITIONS) w.to_hours Copyright (c) 2009 StarterStep, released under the MIT license