More code climate style fixes

This commit is contained in:
Jyri-Petteri Paloposki 2020-10-10 13:58:13 +03:00
parent d8acf60049
commit 67a426a2e9
28 changed files with 157 additions and 172 deletions

View file

@ -228,7 +228,7 @@ module ApplicationHelper
def source_view_key
# uses @project.id or @context.id depending on source_view
source_view_is_one_of(:project, :context) ? "#{@source_view}-#{eval("@#{@source_view}.id")}" : @source_view
source_view_is_one_of(:project, :context) ? "#{@source_view}-#{eval("@#{@source_view}.id", binding, __FILE__, __LINE__)}" : @source_view
end
# create a unique object name which can be used in ajax calls returning js

View file

@ -91,7 +91,7 @@ class MessageGateway < ActionMailer::Base
end
def check_sender_is_in_mailmap(user, email)
if user.present? and !sender_is_in_mailmap?(user,email)
if user.present? && !sender_is_in_mailmap?(user, email)
Rails.logger.warn "#{email.from[0]} not found in mailmap for #{user.login}"
return false
end

View file

@ -49,7 +49,7 @@ class Project < ApplicationRecord
end
def set_last_reviewed_now
self.last_reviewed = Time.now
self.last_reviewed = Time.zone.now
end
def set_completed_at_date

View file

@ -44,8 +44,12 @@ module RecurringTodos
def xth(x)
xth_day = [
I18n.t('todos.recurrence.pattern.first'),I18n.t('todos.recurrence.pattern.second'),I18n.t('todos.recurrence.pattern.third'),
I18n.t('todos.recurrence.pattern.fourth'),I18n.t('todos.recurrence.pattern.last')]
I18n.t('todos.recurrence.pattern.first'),
I18n.t('todos.recurrence.pattern.second'),
I18n.t('todos.recurrence.pattern.third'),
I18n.t('todos.recurrence.pattern.fourth'),
I18n.t('todos.recurrence.pattern.last'),
]
x.nil? ? '??' : xth_day[x - 1]
end

View file

@ -41,7 +41,7 @@ module RecurringTodos
# we did not find anything this week, so check the nth next, starting from
# sunday
start = start + self.every_x_week.week - (start.wday()).days
start = start + self.every_x_week.week - (start.wday).days
start = find_first_day_in_this_week(start)
return start unless start == -1
@ -56,7 +56,7 @@ module RecurringTodos
return self.start_from || Time.zone.now
else
start = previous + 1.day
if start.wday() == 0
if start.wday == 0
# we went to a new week, go to the nth next week and find first match
# that week. Note that we already went into the next week, so -1
start += (every_x_week - 1).week
@ -72,8 +72,8 @@ module RecurringTodos
def find_first_day_in_this_week(start)
# check if there are any days left this week for the next todo
start.wday().upto 6 do |i|
return start + (i - start.wday()).days if on_xday(i)
start.wday.upto 6 do |i|
return start + (i - start.wday).days if on_xday(i)
end
-1
end

View file

@ -32,7 +32,7 @@ module Stats
end
def counts
@counts ||= tags.map { |t| t.count }
@counts ||= tags.map(&:count)
end
end
end

View file

@ -64,8 +64,8 @@ class Todo < ApplicationRecord
where('todos.due > ? AND todos.due <= ?', start_date, end_date)
end
STARRED_TAG_NAME = "starred"
DEFAULT_INCLUDES = [:project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo]
STARRED_TAG_NAME = "starred".freeze
DEFAULT_INCLUDES = [:project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo].freeze
# state machine
include AASM

View file

@ -14,8 +14,8 @@ module Todos
not_done_todos = current_user.todos.active.not_hidden
end
not_done_todos = not_done_todos.
reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
not_done_todos = not_done_todos
.reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
.includes(Todo::DEFAULT_INCLUDES)
not_done_todos = not_done_todos.limit(sanitize(params[:limit])) if params[:limit]

View file

@ -13,6 +13,7 @@ class User < ApplicationRecord
def find_by_params(params)
find(params['id'] || params['context_id']) || nil
end
def update_positions(context_ids)
context_ids.each_with_index { |id, position|
context = self.detect { |c| c.id == id.to_i }
@ -26,6 +27,7 @@ class User < ApplicationRecord
def find_by_params(params)
find(params['id'] || params['project_id'])
end
def update_positions(project_ids)
project_ids.each_with_index { |id, position|
project = self.find_by(id: id.to_i)
@ -33,40 +35,47 @@ class User < ApplicationRecord
project.update_attribute(:position, position + 1)
}
end
def projects_in_state_by_position(state)
self.select { |p| p.state == state }.sort_by { |p| p.position }
end
def next_from(project)
self.offset_from(project, 1)
end
def previous_from(project)
self.offset_from(project, -1)
end
def offset_from(project, offset)
projects = self.projects_in_state_by_position(project.state)
position = projects.index(project)
return nil if position == 0 && offset < 0
projects.at(position + offset)
end
def cache_note_counts
project_note_counts = Note.group(:project_id).count
self.each do |project|
project.cached_note_count = project_note_counts[project.id] || 0
end
end
def alphabetize(scope_conditions = {})
projects = where(scope_conditions)
projects = projects.sort_by { |project| project.name.downcase }
self.update_positions(projects.map{ |p| p.id })
self.update_positions(projects.map(&:id))
return projects
end
def actionize(scope_conditions = {})
todos_in_project = where(scope_conditions).includes(:todos)
todos_in_project = todos_in_project.sort_by { |x| [-x.todos.active.count, -x.id] }
todos_in_project.reject { |p| p.todos.active.count > 0 }
sorted_project_ids = todos_in_project.map { |p| p.id }
sorted_project_ids = todos_in_project.map(&:id)
all_project_ids = self.map { |p| p.id }
all_project_ids = self.map(&:id)
other_project_ids = all_project_ids - sorted_project_ids
update_positions(sorted_project_ids + other_project_ids)

View file

@ -8,7 +8,7 @@ module Common
end
def self.like_operator
# This is something of a hack to use the correct operator for Pg
# HACK: This is something of a hack to use the correct operator for Pg
if ActiveRecord::Base.connection.adapter_name.downcase.to_sym == :postgresql
like = 'ILIKE'
else

View file

@ -1,6 +1,4 @@
class DoneTodos
def self.done_todos_for_container(todos)
completed_todos = todos.completed
return done_today(completed_todos), done_rest_of_week(completed_todos), done_rest_of_month(completed_todos)
@ -57,5 +55,4 @@ class DoneTodos
def self.beginning_of_month
Time.zone.now.beginning_of_month
end
end

View file

@ -1,16 +1,14 @@
# These methods are adapted from has_many_polymorphs' tagging_extensions
module IsTaggable
def self.included(klass)
klass.class_eval do
# Add tags associations
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings do
def to_s
self.to_a.map(&:name).sort.join(Tag::JOIN_DELIMITER)
end
def all_except_starred
self.to_a.reject { |tag| tag.name == Todo::STARRED_TAG_NAME }
end

View file

@ -1,7 +1,6 @@
require_dependency "user"
module LoginSystem
def current_user
get_current_user
end
@ -97,7 +96,6 @@ module LoginSystem
# def authorize?(user)
#
def login_required
if not protect?(action_name)
return true
end
@ -125,7 +123,6 @@ module LoginSystem
end
def login_optional
login_from_cookie
if session['user_id'] and authorize?(get_current_user)
@ -189,7 +186,6 @@ module LoginSystem
# HTTP Basic auth code adapted from Coda Hale's simple_http_auth plugin. Thanks, Coda!
def get_basic_auth_data
auth_locations = ['REDIRECT_REDIRECT_X_HTTP_AUTHORIZATION',
'REDIRECT_X_HTTP_AUTHORIZATION',
'X-HTTP_AUTHORIZATION', 'HTTP_AUTHORIZATION']
@ -226,5 +222,4 @@ private
format.m { redirect_to login_path(:format => 'm') }
end
end
end

View file

@ -2,7 +2,7 @@ require 'active_support/all'
require 'user_time'
class Staleness
SECONDS_PER_DAY = 86400
SECONDS_PER_DAY = 86_400
def self.days_stale(item, current_user)
return 0 if cannot_be_stale(item, current_user)
@ -15,4 +15,3 @@ class Staleness
false
end
end

View file

@ -1,5 +1,4 @@
module Tracks
class AttributeHandler
attr_reader :attributes
@ -133,7 +132,5 @@ module Tracks
:weekly_return_thursday, :weekly_return_friday, :weekly_return_saturday, :weekly_return_sunday
)
end
end
end

View file

@ -1,7 +1,5 @@
module Tracks
class Config
def self.auth_schemes
SITE_CONFIG['authentication_schemes'] || []
end
@ -21,7 +19,5 @@ module Tracks
auth_schemes.first
end
end
end
end

View file

@ -1,10 +1,7 @@
# Inspiration from Bruce Williams [http://codefluency.com/articles/2006/07/01/rails-views-getting-in-context/]
module Tracks
module SourceViewSwitching
class Responder
def initialize(source_view)
@source_view = source_view.underscore.gsub(/\s+/,'_').to_sym rescue nil
end
@ -20,11 +17,9 @@ module Tracks
def method_missing(check_source_view, *args)
yield if check_source_view == @source_view && block_given?
end
end
module Controller
def self.included(base)
base.send(:helper, Tracks::SourceViewSwitching::Helper)
base.send(:helper_method, :source_view)
@ -42,11 +37,9 @@ module Tracks
responder = Tracks::SourceViewSwitching::Responder.new(params[:_source_view] || @source_view)
block_given? ? yield(responder) : responder
end
end
module Helper
def source_view_tag(name)
hidden_field_tag :_source_view, name.underscore.gsub(/\s+/,'_')
end
@ -58,11 +51,8 @@ module Tracks
def source_view_is_one_of(*s)
s.include?((params[:_source_view] || @source_view).to_sym)
end
end
end
end
ActionController::Base.send(:include, Tracks::SourceViewSwitching::Controller)