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 ...@@ -2,10 +2,16 @@ class SystemHookObserver < BaseObserver
observe :user, :project, :users_project observe :user, :project, :users_project
def after_create(model) def after_create(model)
SystemHooksService.execute_hooks_for(model, :create) system_hook_service.execute_hooks_for(model, :create)
end end
def after_destroy(model) 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
end end
class SystemHooksService class SystemHooksService
def self.execute_hooks_for(model, event) def execute_hooks_for(model, event)
execute_hooks(build_event_data(model, event)) execute_hooks(build_event_data(model, event))
end end
private private
def self.execute_hooks(data) def execute_hooks(data)
SystemHook.all.each do |sh| SystemHook.all.each do |sh|
async_execute_hook sh, data async_execute_hook sh, data
end end
end end
def self.async_execute_hook(hook, data) def async_execute_hook(hook, data)
Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data) Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data)
end end
def self.build_event_data(model, event) def build_event_data(model, event)
data = { data = {
event_name: build_event_name(model, event), event_name: build_event_name(model, event),
created_at: model.created_at created_at: model.created_at
...@@ -51,7 +51,7 @@ class SystemHooksService ...@@ -51,7 +51,7 @@ class SystemHooksService
end end
end end
def self.build_event_name(model, event) def build_event_name(model, event)
case model case model
when UsersProject when UsersProject
return "user_add_to_team" if event == :create return "user_add_to_team" if event == :create
......
...@@ -24,10 +24,10 @@ describe SystemHooksService do ...@@ -24,10 +24,10 @@ describe SystemHooksService do
end end
def event_data(*args) def event_data(*args)
SystemHooksService.build_event_data(*args) SystemHooksService.new.send :build_event_data, *args
end end
def event_name(*args) def event_name(*args)
SystemHooksService.build_event_name(*args) SystemHooksService.new.send :build_event_name, *args
end end
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