Last active
October 8, 2018 18:38
-
-
Save iSarCasm/d3697b0dffbcbf72166016adb09ce0d5 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 SomeController | |
def create | |
@objective = CreateObjective.call( | |
tenant: Apartment::Tenant.current, | |
params: params | |
).objective | |
end | |
end | |
module CreateObjective | |
def call | |
if context.tenant == 'vtl' | |
CreateObjective::VTL.call(context) | |
else | |
CreateObjective::Common.call(context) | |
end | |
end | |
class Common | |
def call | |
ActiveRecord::Base.transaction do | |
context.objective = Objective.create(params) | |
inside_transaction(context) | |
end | |
end | |
def inside_transaction(context) | |
end | |
end | |
class VTL < Common | |
def call | |
super | |
Notification.create(employee: context.employee, message: 'Objective created') | |
end | |
def self.inside_transaction(context) | |
update_objectives_counter(context.employee) | |
end | |
private | |
def self.update_objectives_counter(employee) | |
employee.update(objective_count: employee.objectives.count) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment