Created
March 26, 2011 01:18
-
-
Save ericchen/887934 to your computer and use it in GitHub Desktop.
define dynamic class methods in model
This file contains 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
class << self | |
attrs_without_id = AppConfig.column_names.delete_if {|x| x=='id'} | |
default_values = {'pending_earned_buck_period'=>30*24*60, 'pending_refer_buck_period'=>60*24*60, 'refer_buck_valid_period'=>100*24*60, 'order_delivery_hold_period'=>3*24*60,'code_length'=>8} | |
attrs_without_id.each do |attr| | |
define_method(attr) do | |
load_config | |
@config && @config.send(attr) || default_values[attr] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment