Created
April 14, 2010 09:12
-
-
Save sumskyi/365613 to your computer and use it in GitHub Desktop.
scope gate example
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_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