scinote-web/app/services/repository_columns/column_service.rb

54 lines
1.1 KiB
Ruby
Raw Normal View History

2019-10-09 20:09:27 +08:00
# frozen_string_literal: true
module RepositoryColumns
class ColumnService
2019-10-09 20:09:27 +08:00
extend Service
2019-10-09 21:18:51 +08:00
attr_reader :errors, :column
2019-10-09 20:09:27 +08:00
2019-10-09 21:18:51 +08:00
def initialize(user:, repository:, column_name:, team:)
2019-10-09 20:09:27 +08:00
@user = user
@repository = repository
2019-10-09 21:18:51 +08:00
@column_name = column_name
@team = team
2019-10-09 20:09:27 +08:00
@errors = {}
2019-10-09 21:18:51 +08:00
@column = nil
2019-10-09 20:09:27 +08:00
end
def call
raise NotImplementedError
end
def succeed?
@errors.none?
end
private
def valid?
unless @user && @repository
@errors[:invalid_arguments] =
{ 'user': @user,
'repository': @repository }
.map do |key, value|
"Can't find #{key.capitalize}" if value.nil?
end.compact
end
succeed?
end
2019-10-09 21:18:51 +08:00
def log_activity(type)
Activities::CreateActivityService
.call(activity_type: type,
owner: @user,
subject: @repository,
team: @team,
message_items: {
repository_column: @column.id,
repository: @repository.id
})
end
2019-10-09 20:09:27 +08:00
end
end