Last active
December 11, 2015 14:49
-
-
Save patbenatar/4617063 to your computer and use it in GitHub Desktop.
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 Order | |
include Stats::Host | |
# The above would mix this in: | |
has_one :stat, class_name: "Order::Stat" | |
after_commit :create_stat, on: :create | |
def create_stat | |
stat.create! | |
end | |
end | |
class Earning | |
include Stats::Provider | |
stats_for :order, | |
observe: [:amount, :earner_type] | |
# The above would mix this in: | |
after_commit :refresh_stat, on: :create | |
after_commit :refresh_stat, on: :update, if: :should_refresh_stat? | |
after_commit :refresh_stat, on: :destroy | |
def refresh_stat | |
order.stat.refresh | |
end | |
def should_refresh_stat? | |
amount_changed? || earner_type_changed? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment