Skip to content

Instantly share code, notes, and snippets.

@ericchen
Created March 26, 2011 01:18
Show Gist options
  • Save ericchen/887934 to your computer and use it in GitHub Desktop.
Save ericchen/887934 to your computer and use it in GitHub Desktop.
define dynamic class methods in model
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