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

@ -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,26 +1,24 @@
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)
end
def self.done_today(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
def self.done_today(todos, includes={ :include => Todo::DEFAULT_INCLUDES })
# TODO: refactor to remove outer hash from includes param
todos.completed_after(beginning_of_day).includes(includes[:include])
end
def self.done_rest_of_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
def self.done_rest_of_week(todos, includes={ :include => Todo::DEFAULT_INCLUDES })
done_between(todos, includes, beginning_of_day, beginning_of_week)
end
def self.done_rest_of_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
def self.done_rest_of_month(todos, includes={ :include => Todo::DEFAULT_INCLUDES })
done_between(todos, includes, beginning_of_week, beginning_of_month)
end
def self.completed_period(date)
return nil if date.nil?
return nil if date.nil?
return "today" if date >= end_of_day # treat todos with completed_at in future as done today (happens in tests)
return "today" if date.between?(beginning_of_day, end_of_day)
@ -57,5 +55,4 @@ class DoneTodos
def self.beginning_of_month
Time.zone.now.beginning_of_month
end
end

View file

@ -1,18 +1,16 @@
# 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}
self.to_a.reject { |tag| tag.name == Todo::STARRED_TAG_NAME }
end
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']
@ -216,7 +212,7 @@ module LoginSystem
render :body => t('login.unsuccessful'), :status => 401
end
private
private
# Redirect the user to the login page.
def redirect_to_login
@ -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
@ -10,7 +9,7 @@ module Tracks
end
def get(attribute)
@attributes[attribute.to_sym]
@attributes[attribute.to_sym]
end
def [](attribute)
@ -37,7 +36,7 @@ module Tracks
@attributes.key?(key.to_sym)
end
def selector_key_present?(key)
def selector_key_present?(key)
key?(key)
end
@ -78,9 +77,9 @@ module Tracks
object = relation.build(:name => name)
new_object_created = true
end
return object, new_object_created
end
end
def specified_by_name?(object_type)
self.send("#{object_type}_specified_by_name?")
@ -115,25 +114,23 @@ module Tracks
ActionController::Parameters.new(attributes).permit(
:context, :project,
# model attributes
:context_id, :project_id, :description, :notes, :state, :start_from,
:context_id, :project_id, :description, :notes, :state, :start_from,
:ends_on, :end_date, :number_of_occurrences, :occurrences_count, :target,
:show_from_delta, :recurring_period, :recurrence_selector, :every_other1,
:every_other2, :every_other3, :every_day, :only_work_days, :every_count,
:show_from_delta, :recurring_period, :recurrence_selector, :every_other1,
:every_other2, :every_other3, :every_day, :only_work_days, :every_count,
:weekday, :show_always, :context_name, :project_name, :tag_list,
# form attributes
:recurring_period, :daily_selector, :monthly_selector, :yearly_selector,
:recurring_target, :daily_every_x_days, :monthly_day_of_week,
:monthly_every_x_day, :monthly_every_x_month2, :monthly_every_x_month,
:monthly_every_xth_day, :recurring_show_days_before,
:recurring_period, :daily_selector, :monthly_selector, :yearly_selector,
:recurring_target, :daily_every_x_days, :monthly_day_of_week,
:monthly_every_x_day, :monthly_every_x_month2, :monthly_every_x_month,
:monthly_every_xth_day, :recurring_show_days_before,
:recurring_show_always, :weekly_every_x_week, :weekly_return_monday,
:yearly_day_of_week, :yearly_every_x_day, :yearly_every_xth_day,
:yearly_day_of_week, :yearly_every_x_day, :yearly_every_xth_day,
:yearly_month_of_year2, :yearly_month_of_year,
# derived attributes
:weekly_return_monday, :weekly_return_tuesday, :weekly_return_wednesday,
:weekly_return_monday, :weekly_return_tuesday, :weekly_return_wednesday,
:weekly_return_thursday, :weekly_return_friday, :weekly_return_saturday, :weekly_return_sunday
)
)
end
end
end

View file

@ -1,11 +1,9 @@
module Tracks
class Config
def self.auth_schemes
SITE_CONFIG['authentication_schemes'] || []
end
def self.openid_enabled?
auth_schemes.include?('open_id')
end
@ -13,7 +11,7 @@ module Tracks
def self.cas_enabled?
auth_schemes.include?('cas')
end
def self.prefered_auth?
if SITE_CONFIG['prefered_auth']
SITE_CONFIG['prefered_auth']
@ -21,7 +19,5 @@ module Tracks
auth_schemes.first
end
end
end
end

View file

@ -1,14 +1,11 @@
# 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
def nil?
yield if @source_view.nil? && block_given?
end
@ -16,53 +13,46 @@ module Tracks
def context
yield if :context == @source_view && block_given?
end
def method_missing(check_source_view,*args)
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)
end
def source_view_is( s )
def source_view_is(s)
s == (params[:_source_view] || @source_view).to_sym
end
def source_view_is_one_of( *s )
def source_view_is_one_of(*s)
s.include?(params[:_source_view].to_sym)
end
def source_view
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
def source_view_is( s )
def source_view_is(s)
s == (params[:_source_view] || @source_view).to_sym
end
def source_view_is_one_of( *s )
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)