Skip to content

Instantly share code, notes, and snippets.

@CQBinh
Created December 1, 2016 02:41
Show Gist options
  • Save CQBinh/4be07479bfdc1e8b32b35ee491f618ca to your computer and use it in GitHub Desktop.
Save CQBinh/4be07479bfdc1e8b32b35ee491f618ca to your computer and use it in GitHub Desktop.
module ZillyBuck
extend ActiveSupport::Concern
def create_reimburement_attachment_reward(owner)
kind = :add_an_reimburement_attachment
amount = ZillyBuckHistory::REWARD_AMOUNT[:add_an_reimburement_attachment]
create_history_if_need(owner, kind, amount)
end
def create_approval_attachment_reward(owner)
kind = :add_an_approval_attachment
amount = ZillyBuckHistory::REWARD_AMOUNT[:add_an_approval_attachment]
create_history_if_need(owner, kind, amount)
end
def create_invite_friend_reward(owner)
kind = :invite_friend
amount = ZillyBuckHistory::REWARD_AMOUNT[:invite_friend]
create_history_if_need(owner, kind, amount)
end
private
def create_history_if_need(owner, kind, amount)
create_history if owner.can_receive_reward?(kind)
end
def create_history(owner, kind, amount)
owner.zilly_buck_histories.create!(kind: kind, amount: amount)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment