Skip to content

Instantly share code, notes, and snippets.

@satour
Created October 19, 2016 12:31
Show Gist options
  • Save satour/cef12d5f3c4fd23ccd5d611c555940b8 to your computer and use it in GitHub Desktop.
Save satour/cef12d5f3c4fd23ccd5d611c555940b8 to your computer and use it in GitHub Desktop.
module Salesforce
def method_missing(name, *args, &block)
return super if valid_attribute_name? name
if name.to_s[-1] == '='
send "#{ name.to_s.gsub '=', '__c=' }".to_sym, *args
elsif name.to_s.end_with? '_changed?'
send "#{name.to_s.gsub '_changed?', '__c_changed?'}".to_sym, *args
else
send "#{ name }__c".to_sym
end
end
private
def valid_attribute_name?(name)
attr = name.to_s.chomp('_changed?').chomp('?').chomp('=')
attributes.include?(attr) || attr.include?('__c')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment