Skip to content

Instantly share code, notes, and snippets.

@iSarCasm
Last active October 8, 2018 18:38
Show Gist options
  • Save iSarCasm/d3697b0dffbcbf72166016adb09ce0d5 to your computer and use it in GitHub Desktop.
Save iSarCasm/d3697b0dffbcbf72166016adb09ce0d5 to your computer and use it in GitHub Desktop.
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