Skip to content

Commit

Permalink
Rubocop (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
phoet committed Dec 30, 2016
1 parent 84df11f commit b5a7a62
Show file tree
Hide file tree
Showing 106 changed files with 808 additions and 772 deletions.
41 changes: 41 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Style/ConditionalAssignment:
Enabled: false

Style/BlockDelimiters:
Enabled: false

Style/SpecialGlobalVars:
Enabled: false

Lint/AssignmentInCondition:
Enabled: false

Style/MutableConstant:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/Documentation:
Enabled: false

Style/TrailingCommaInLiteral:
Enabled: false

Style/DoubleNegation:
Enabled: false

Metrics/ClassLength:
Max: 500

Metrics/LineLength:
Max: 120

Metrics/BlockLength:
Max: 80

Metrics/MethodLength:
Max: 30

Metrics/AbcSize:
Max: 30
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "http://rubygems.org"
ruby "2.3.1"

gem "puma", "~> 2.11"
gem "puma", "~> 3.6"
gem "rails", "~> 4.2.5"
gem "responders", "~> 2.0"
gem "rails-observers", "~> 0.1.2"
Expand Down
10 changes: 6 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ GEM
pry-remote (0.1.8)
pry (~> 0.9)
slop (~> 3.0)
puma (2.11.1)
rack (>= 1.1, < 2.0)
puma (3.6.2)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.6.4)
Expand Down Expand Up @@ -365,7 +364,7 @@ DEPENDENCIES
pry-nav
pry-rails
pry-remote
puma (~> 2.11)
puma (~> 3.6)
quiet_assets
rack-cache (~> 1.2)
rails (~> 4.2.5)
Expand All @@ -382,5 +381,8 @@ DEPENDENCIES
uglifier (~> 2.5.0)
whitelabel (~> 0.3)

RUBY VERSION
ruby 2.3.0p0

BUNDLED WITH
1.11.2
1.13.7
4 changes: 2 additions & 2 deletions app/concerns/mobile_detection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ def check_for_mobile
end

def prepare_for_mobile
prepend_view_path Rails.root.join("app/views/mobile")
prepend_view_path Rails.root.join('app/views/mobile')
end

def mobile_device?
if session[:mobile_override]
session[:mobile_override] == "1"
session[:mobile_override] == '1'
else
request.user_agent =~ /Mobile|webOS/
end
Expand Down
1 change: 0 additions & 1 deletion app/concerns/time_zone_detection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ def allowed_time_zone?(time_zone)
def default_time_zone
Whitelabel.label ? Whitelabel[:default_time_zone] : Rails.configuration.time_zone
end

end
8 changes: 3 additions & 5 deletions app/concerns/user_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ module UserHandling

def authenticate_admin_user!
unless signed_in? && current_user.admin?
redirect_to root_path, alert: t("flash.only_admins")
redirect_to root_path, alert: t('flash.only_admins')
end
end

def authenticate!
unless signed_in?
redirect_to root_path, alert: t("flash.not_authenticated")
end
redirect_to root_path, alert: t('flash.not_authenticated') unless signed_in?
end

def authenticate_current_user!
unless signed_in? && current_user?
redirect_to root_path, alert: t("flash.not_authenticated")
redirect_to root_path, alert: t('flash.not_authenticated')
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/concerns/whitelabel_translation.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module WhitelabelTranslation
def translate_whitelabel(token, options = {})
sub = Whitelabel.label ? Whitelabel[:label_id] : "default"
t("label.#{sub}.#{token}".to_sym, options.merge(default: ["label.default.#{token}".to_sym,token.to_sym]))
sub = Whitelabel.label ? Whitelabel[:label_id] : 'default'
t("label.#{sub}.#{token}".to_sym, options.merge(default: ["label.default.#{token}".to_sym, token.to_sym]))
end
alias :tw :translate_whitelabel
alias tw translate_whitelabel
end
12 changes: 6 additions & 6 deletions app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Admin::EventsController < Admin::ResourcesController
def duplicate
event = Event.duplicate!
redirect_to url_for(controller: "/admin/events", action: :edit, id: event.id)
redirect_to url_for(controller: '/admin/events', action: :edit, id: event.id)
end

def publish
event = Event.find(params[:id])
UsergroupMailer.invitation_mail(event).deliver_now!
event.update_attributes! published: true

redirect_to url_for(controller: "/admin/events", action: :edit, id: event.id), notice: "Published!"
redirect_to url_for(controller: '/admin/events', action: :edit, id: event.id), notice: 'Published!'
end

def send_ios_push_notification
Expand All @@ -26,12 +26,12 @@ def send_ios_push_notification

notification_call = OneSignal::Notification.create(params: options)

message = if notification_call.code == '200'
{ notice: "iOS Push Notification sent!" }
if notification_call.code == '200'
message = { notice: 'iOS Push Notification sent!' }
else
{ alert: "iOS Push Notification could not be sent!" }
message = { alert: 'iOS Push Notification could not be sent!' }
end

redirect_to url_for(controller: "/admin/events", action: :show, id: event.id), message
redirect_to url_for(controller: '/admin/events', action: :show, id: event.id), message
end
end
3 changes: 1 addition & 2 deletions app/controllers/admin/highlights_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
class Admin::HighlightsController < Admin::ResourcesController

before_action :set_highlight_defaults, only: :new

def disable
@highlight = Highlight.find(params[:id])
@highlight.disable!
redirect_to url_for(controller: "/admin/highlights", action: :edit, id: @highlight), notice: "Disabled!"
redirect_to url_for(controller: '/admin/highlights', action: :edit, id: @highlight), notice: 'Disabled!'
end

protected
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def add_to_next_event
@topic.event = @event
@event.particpate(@user)
@topic.save!
redirect_to url_for(controller: "/admin/topics", action: :edit, id: @topic.id), notice: "Added to latest Event!"
redirect_to url_for(controller: '/admin/topics', action: :edit, id: @topic.id), notice: 'Added to latest Event!'
else
redirect_to(url_for(controller: "/admin/topics", action: :index), alert: "no next event found")
redirect_to(url_for(controller: '/admin/topics', action: :index), alert: 'no next event found')
end
end
end
12 changes: 5 additions & 7 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ def index
def flush
Rails.cache.clear

respond_with({result: :ok})
respond_with(result: :ok)
end

private

def api_sign_in
if request.format.json?
key = request.headers["x-api-key"] || params["x-api-key"]
if key != ENV["HOR_API_KEY"]
head :unauthorized
end
end
return unless request.format.json?

key = request.headers['x-api-key'] || params['x-api-key']
head :unauthorized if key != ENV['HOR_API_KEY']
end
end
14 changes: 7 additions & 7 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class HomeController < ApplicationController
expose(:current_event) { Event.current.first }
expose(:events) { Event.latest.limit(10) }
expose(:people) { User.peers }
expose(:undone_topics) { Topic.ordered.undone }
expose(:upcoming_topics){ Topic.ordered.upcoming }
expose(:done_topics) { Topic.ordered.done.limit(10) }
expose(:organizers) { User.organizers }
expose(:current_event) { Event.current.first }
expose(:events) { Event.latest.limit(10) }
expose(:people) { User.peers }
expose(:undone_topics) { Topic.ordered.undone }
expose(:upcoming_topics) { Topic.ordered.upcoming }
expose(:done_topics) { Topic.ordered.done.limit(10) }
expose(:organizers) { User.organizers }
expose(:locations)

def index; end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def create
like.topic = topic
like.user = current_user
if topic.already_liked?(current_user)
flash[:alert] = t("flash.double_like")
flash[:alert] = t('flash.double_like')
elsif like.save
flash[:notice] = t("flash.liked")
flash[:notice] = t('flash.liked')
else
flash[:alert] = like.errors.full_messages.join(' ')
end
Expand All @@ -19,7 +19,7 @@ def create

def destroy
if topic.already_liked?(current_user) && like.destroy
flash[:notice] = t("flash.unliked")
flash[:notice] = t('flash.unliked')
else
flash[:alert] = like.errors.full_messages.join(' ')
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class LocationsController < ApplicationController
expose(:stats) { Event.stats }

def index; end

def show; end

def none; end
end
10 changes: 5 additions & 5 deletions app/controllers/participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class ParticipantsController < ApplicationController

def create
if event.closed?
flash[:alert] = t("flash.already_closed")
flash[:alert] = t('flash.already_closed')
elsif event.particpate(current_user)
flash[:notice] = t("flash.now_participating")
flash[:notice] = t('flash.now_participating')
else
flash[:alert] = t("flash.already_participating")
flash[:alert] = t('flash.already_participating')
end
redirect_to event_path(event)
end
Expand All @@ -18,9 +18,9 @@ def destroy
participant = Participant.find params[:id]
if participant.owned_by? current_user
participant.destroy
redirect_to event_path(participant.event), notice: t("flash.dont_participate")
redirect_to event_path(participant.event), notice: t('flash.dont_participate')
else
redirect_to event_path(participant.event), alert: t("flash.forbidden")
redirect_to event_path(participant.event), alert: t('flash.forbidden')
end
end
end
10 changes: 5 additions & 5 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
class SessionsController < ApplicationController
def offline_login
self.current_user = User.find_by_nickname(params[:nickname])
redirect_to root_path, notice: "Offline Login!"
redirect_to root_path, notice: 'Offline Login!'
end

def create
begin
authorization = Authorization.handle_authorization request.env['omniauth.auth']
self.current_user = authorization.user
options = {notice: t("flash.logged_in", name: current_user.name)}
options = { notice: t('flash.logged_in', name: current_user.name) }
cookies.permanent.signed[:remember_me] = [current_user.id, current_user.salt]
rescue User::DuplicateNickname => error
options = {alert: t("flash.duplicate_nick", name: error.nickname)}
options = { alert: t('flash.duplicate_nick', name: error.nickname) }
end
redirect_to request.env['omniauth.origin'] || root_path, options
end

def destroy
session[:user_id] = nil
cookies.permanent.signed[:remember_me] = ['', '']
message = flash[:notice] || t("flash.logged_out")
message = flash[:notice] || t('flash.logged_out')
redirect_to root_path, notice: message
end

def failure
redirect_to root_path, alert: t("flash.login_error")
redirect_to root_path, alert: t('flash.login_error')
end

def auth
Expand Down
19 changes: 11 additions & 8 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ class TopicsController < ApplicationController
before_action :validate_topic_ownership!, only: [:edit, :update]

expose(:topic, attributes: :topic_params)
expose(:events) { Event.with_topics.ordered.page(params[:page]).per(10) }
expose(:undone_topics) { Topic.ordered.undone }
expose(:done_topics) { Topic.ordered.done }
expose(:upcoming_topics){ Topic.ordered.upcoming }
expose(:events) { Event.with_topics.ordered.page(params[:page]).per(10) }
expose(:undone_topics) { Topic.ordered.undone }
expose(:done_topics) { Topic.ordered.done }
expose(:upcoming_topics) { Topic.ordered.upcoming }

def index; end

def show; end

def new; end

def edit; end

def create
topic.label = Whitelabel[:label_id]
topic.user = current_user
if topic.save
if current_user.email.blank?
redirect_to(edit_user_path(current_user), notice: t("flash.add_email"))
redirect_to(edit_user_path(current_user), notice: t('flash.add_email'))
else
redirect_to(topic_path(topic), notice: t("flash.topic_added"))
redirect_to(topic_path(topic), notice: t('flash.topic_added'))
end
else
redirect_to(new_topic_path, alert: topic.errors.full_messages.join(', '))
Expand All @@ -29,7 +32,7 @@ def create

def update
if topic.save
redirect_to(topic_path(topic), notice: t("flash.topic_updated"))
redirect_to(topic_path(topic), notice: t('flash.topic_updated'))
else
redirect_to(edit_topic_path, alert: topic.errors.full_messages.join(', '))
end
Expand All @@ -39,7 +42,7 @@ def update

def validate_topic_ownership!
if topic.user != current_user && !current_user.admin?
redirect_to(root_path, alert: t("flash.not_authenticated"))
redirect_to(root_path, alert: t('flash.not_authenticated'))
end
end

Expand Down
Loading

0 comments on commit b5a7a62

Please sign in to comment.