Use instance methods for system_hooks_service

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-01-15 14:26:05 +02:00
parent 065d9c22fa
commit 37ef33cba1
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
3 changed files with 15 additions and 9 deletions

View file

@ -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

View file

@ -1,21 +1,21 @@
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

View file

@ -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