Fix syntax (w/Rubocop) in services

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/2136/head
Alex Coles 10 years ago
parent a2b4e97eea
commit 10f578d00b
  1. 2
      app/services/authorization_service.rb
  2. 16
      app/services/planning_comparison_service.rb
  3. 8
      app/services/reports/assignee_report.rb
  4. 7
      app/services/reports/author_report.rb
  5. 5
      app/services/reports/category_report.rb
  6. 5
      app/services/reports/priority_report.rb
  7. 4
      app/services/reports/report.rb
  8. 8
      app/services/reports/reports_service.rb
  9. 8
      app/services/reports/responsible_report.rb
  10. 5
      app/services/reports/subproject_report.rb
  11. 6
      app/services/reports/type_report.rb
  12. 6
      app/services/reports/version_report.rb
  13. 2
      app/services/update_work_package_service.rb
  14. 9
      app/services/user_search_service.rb

@ -37,7 +37,7 @@ class AuthorizationService
# context - single project or array of projects - default nil
# global - global - default false
# user - user - default current user
def initialize(permission, context: nil , global: false, user: User.current)
def initialize(permission, context: nil, global: false, user: User.current)
@permission = permission
@context = context
@global = global

@ -41,7 +41,7 @@ class PlanningComparisonService
where #{Journal.table_name}.created_at=latest.latest_date
and #{Journal.table_name}.id=latest.latest_id;
SQL
@@mapped_attributes = Journal::WorkPackageJournal.journaled_attributes.map{|attribute| "#{Journal::WorkPackageJournal.table_name}.#{attribute}"}.join ','
@@mapped_attributes = Journal::WorkPackageJournal.journaled_attributes.map { |attribute| "#{Journal::WorkPackageJournal.table_name}.#{attribute}" }.join ','
@@work_package_select = <<SQL
Select #{Journal.table_name}.journable_id as id,
@ -58,8 +58,7 @@ SQL
# the comparison always works on the current date, filters the current workpackages
# and returns the state of these work_packages at the given time
# filters are given in the format expected by Query and are just passed through to query
def self.compare(projects, at_time, filter={})
def self.compare(projects, at_time, filter = {})
# The query uses three steps to find the journalized entries for the filtered workpackages
# at the given point in time:
# 1 filter the ids using query
@ -79,7 +78,7 @@ SQL
.map(&:id)
# 3&4 fetch the journaled data and make rails think it is actually a work_package
work_packages = WorkPackage.find_by_sql([@@work_package_select,journal_ids])
work_packages = WorkPackage.find_by_sql([@@work_package_select, journal_ids])
restore_references(work_packages)
end
@ -107,7 +106,6 @@ SQL
# introduced by the json/xml-rendering
# the simple .includes does not work the work due to the find_by_sql
def self.restore_references(work_packages)
projects = resolve_projects(work_packages)
types = resolve_types(work_packages)
statuses = resolve_statuses(work_packages)
@ -119,22 +117,20 @@ SQL
end
work_packages
end
def self.resolve_projects(work_packages)
project_ids = work_packages.map(&:project_id).uniq.compact
projects = Hash[Project.find(project_ids).map {|wp| [wp.id,wp]}]
projects = Hash[Project.find(project_ids).map { |wp| [wp.id, wp] }]
end
def self.resolve_types(work_packages)
type_ids = work_packages.map(&:type_id).uniq.compact
types = Hash[Type.find(type_ids).map{|type| [type.id,type]}]
types = Hash[Type.find(type_ids).map { |type| [type.id, type] }]
end
def self.resolve_statuses(work_packages)
status_ids = work_packages.map(&:status_id).uniq.compact
statuses = Hash[Status.find(status_ids).map{|status| [status.id,status]}]
statuses = Hash[Status.find(status_ids).map { |status| [status.id, status] }]
end
end

@ -28,17 +28,16 @@
#++
class Reports::AssigneeReport < Reports::Report
def self.report_type
"assigned_to"
'assigned_to'
end
def field
@field ||= "assigned_to_id"
@field ||= 'assigned_to_id'
end
def rows
@rows ||= @project.members.collect { |m| m.user }.sort
@rows ||= @project.members.collect(&:user).sort
end
def data
@ -48,5 +47,4 @@ class Reports::AssigneeReport < Reports::Report
def title
@title ||= WorkPackage.human_attribute_name(:assigned_to)
end
end

@ -28,17 +28,16 @@
#++
class Reports::AuthorReport < Reports::Report
def self.report_type
"author"
'author'
end
def field
"author_id"
'author_id'
end
def rows
@rows ||= @project.members.collect { |m| m.user }.sort
@rows ||= @project.members.collect(&:user).sort
end
def data

@ -28,13 +28,12 @@
#++
class Reports::CategoryReport < Reports::Report
def self.report_type
"category"
'category'
end
def field
"category_id"
'category_id'
end
def rows

@ -28,13 +28,12 @@
#++
class Reports::PriorityReport < Reports::Report
def self.report_type
"priority"
'priority'
end
def field
"priority_id"
'priority_id'
end
def rows

@ -28,13 +28,12 @@
#++
class Reports::Report
def initialize(project)
@project = project
end
def self.report_type
"default"
'default'
end
def report_type
@ -61,5 +60,4 @@ class Reports::Report
def title
raise NotImplementedError
end
end

@ -28,7 +28,6 @@
#++
class Reports::ReportsService
class_attribute :report_types
def self.add_report(report)
@ -40,7 +39,6 @@ class Reports::ReportsService
self.report_types.has_key? report_type
end
# automate this? by cycling through each instance of Reports::Report? or is this to automagically?
# and there is no reason, why plugins shouldn't be able to use this to add their own customized reports...
add_report Reports::SubprojectReport
@ -52,11 +50,8 @@ class Reports::ReportsService
add_report Reports::CategoryReport
add_report Reports::VersionReport
def initialize(project)
raise "You must provide a project to report upon" unless project && project.is_a?(Project)
raise 'You must provide a project to report upon' unless project && project.is_a?(Project)
@project = project
end
@ -64,5 +59,4 @@ class Reports::ReportsService
report_klass = self.class.report_types[report_type]
report_klass.new(@project) if report_klass
end
end

@ -28,17 +28,16 @@
#++
class Reports::ResponsibleReport < Reports::Report
def self.report_type
"responsible"
'responsible'
end
def field
@field ||= "responsible_id"
@field ||= 'responsible_id'
end
def rows
@rows ||= @project.members.collect { |m| m.user }.sort
@rows ||= @project.members.collect(&:user).sort
end
def data
@ -48,5 +47,4 @@ class Reports::ResponsibleReport < Reports::Report
def title
@title ||= WorkPackage.human_attribute_name(:responsible)
end
end

@ -28,13 +28,12 @@
#++
class Reports::SubprojectReport < Reports::Report
def self.report_type
"subproject"
'subproject'
end
def field
"project_id"
'project_id'
end
def rows

@ -28,13 +28,12 @@
#++
class Reports::TypeReport < Reports::Report
def self.report_type
"type"
'type'
end
def field
@field || "type_id"
@field || 'type_id'
end
def rows
@ -48,5 +47,4 @@ class Reports::TypeReport < Reports::Report
def title
@title = WorkPackage.human_attribute_name(:type)
end
end

@ -28,13 +28,12 @@
#++
class Reports::VersionReport < Reports::Report
def self.report_type
"version"
'version'
end
def field
@field ||= "fixed_version_id"
@field ||= 'fixed_version_id'
end
def rows
@ -48,5 +47,4 @@ class Reports::VersionReport < Reports::Report
def title
@title ||= WorkPackage.human_attribute_name(:version)
end
end

@ -30,7 +30,7 @@
class UpdateWorkPackageService
attr_accessor :user, :work_package, :permitted_params, :send_notifications
def initialize(user, work_package, permitted_params, send_notifications=true)
def initialize(user, work_package, permitted_params, send_notifications = true)
self.user = user
self.work_package = work_package
self.permitted_params = permitted_params

@ -67,21 +67,20 @@ class UserSearchService
else
@status = params[:status] ? params[:status].to_i : User::STATUSES[:active]
scope = scope.not_blocked if @status == User::STATUSES[:active]
c << ["status = ?", @status]
c << ['status = ?', @status]
end
unless params[:name].blank?
name = "%#{params[:name].strip.downcase}%"
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
c << ['LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?', name, name, name, name]
end
scope.where(c.conditions)
# currently, the sort/paging-helpers are highly dependent on being included in a controller
# and having access to things like the session or the params: this makes it harder
# to test outside a controller and especially hard to re-use this functionality
#.page(page_param)
#.per_page(per_page_param)
# .page(page_param)
# .per_page(per_page_param)
# .order(sort_clause)
end
end

Loading…
Cancel
Save