Created
June 25, 2009 18:23
-
-
Save texel/136054 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module TimeAttributeExtensions | |
| module ClassMethods | |
| def define_attribute_methods | |
| if super | |
| columns_hash.each do |name, column| | |
| if [:datetime, :timestamp].include?(column.type) | |
| define_method("#{name}=") do |time| | |
| super parse_time_from_hash(time) | |
| end | |
| end | |
| end | |
| return true | |
| end | |
| end | |
| end | |
| module InstanceMethods | |
| def parse_time_from_hash(time) | |
| # Do time parsing here | |
| end | |
| end | |
| def self.included(receiver) | |
| receiver.send(:include, InstanceMethods) | |
| receiver.extend ClassMethods | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment