Commit 37ef33cb authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use instance methods for system_hooks_service

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 065d9c22
......@@ -2,10 +2,16 @@ class SystemHookObserver < BaseObserver
observe :user, :project, :users_project
def after_create(model)
SystemHooksService.execute_hooks_for(model, :create)
system_hook_service.execute_hooks_for(model, :create)
end
def after_destroy(model)
SystemHooksService.execute_hooks_for(model, :destroy)
system_hook_service.execute_hooks_for(model, :destroy)
end
private
def system_hook_service
SystemHooksService.new
end
end
class SystemHooksService
def self.execute_hooks_for(model, event)
def execute_hooks_for(model, event)
execute_hooks(build_event_data(model, event))
end
private
def self.execute_hooks(data)
def execute_hooks(data)
SystemHook.all.each do |sh|
async_execute_hook sh, data
end
end
def self.async_execute_hook(hook, data)
def async_execute_hook(hook, data)
Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data)
end
def self.build_event_data(model, event)
def build_event_data(model, event)
data = {
event_name: build_event_name(model, event),
created_at: model.created_at
......@@ -51,7 +51,7 @@ class SystemHooksService
end
end
def self.build_event_name(model, event)
def build_event_name(model, event)
case model
when UsersProject
return "user_add_to_team" if event == :create
......
......@@ -24,10 +24,10 @@ describe SystemHooksService do
end
def event_data(*args)
SystemHooksService.build_event_data(*args)
SystemHooksService.new.send :build_event_data, *args
end
def event_name(*args)
SystemHooksService.build_event_name(*args)
SystemHooksService.new.send :build_event_name, *args
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment