Skip to content

Instantly share code, notes, and snippets.

@sumskyi
Created April 14, 2010 09:12
Show Gist options
  • Save sumskyi/365613 to your computer and use it in GitHub Desktop.
Save sumskyi/365613 to your computer and use it in GitHub Desktop.
scope gate example
class_eval do
{
:total_npm => [BucketContribution::Type::NON_PAYABLE_MARKETING, TransactionType::MANUAL_CREDIT_TO_NON_PAYABLE_MARKETING],
:total_pm => [BucketContribution::Type::PAYABLE_MARKETING, TransactionType::MANUAL_CREDIT_TO_PAYABLE_MARKETING],
:total_deposits => [BucketContribution::Type::DEPOSIT, TransactionType::MANUAL_CREDIT_TO_DEPOSIT],
:total_earnings => [BucketContribution::Type::SERVICES_EARNED, TransactionType::MANUAL_CREDIT_SERVICES_EARNED]
}.each do |name, i|
define_method "#{name}=" do |amount|
BucketContribution.delete_all(["user_id = ? AND bucket_type = ?", self.id, i[0] ])
user_transaction = UserTransaction.new({
:user_id => self.id,
:amount => amount,
:transaction_type => i[1],
:domain_id => self.domain_id
})
commerce_engine = CommerceEngine.new(self.domain)
commerce_engine.process(user_transaction)
end
define_method name do
self.get_balance(i[0]).to_f
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment