From e6f6475705ea715920b34b0f7361682a6948bf74 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 1 Apr 2014 19:02:23 +0000 Subject: [PATCH] Fix coding standards in application --- app/controllers/api/application_controller.rb | 40 ++++++++++--------- app/controllers/api/playlists_controller.rb | 18 +++++---- app/controllers/api/sessions_controller.rb | 20 +++++----- app/controllers/api/sounds_controller.rb | 12 +++--- app/controllers/api/tracks_controller.rb | 8 ++-- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/app/controllers/api/application_controller.rb b/app/controllers/api/application_controller.rb index 1eac42f..60e876d 100644 --- a/app/controllers/api/application_controller.rb +++ b/app/controllers/api/application_controller.rb @@ -1,26 +1,28 @@ -class API::ApplicationController < ApplicationController - skip_before_filter :verify_authenticity_token - skip_before_filter :authenticate!, only: [:cor_preflight] +module API + class ApplicationController < ::ApplicationController + skip_before_filter :verify_authenticity_token + skip_before_filter :authenticate!, only: [:cor_preflight] - before_filter :cor_filter + before_filter :cor_filter - def cor_filter - headers['Access-Control-Allow-Origin'] = request.headers['Origin'] ? - request.headers['Origin'] : - '' - headers['Access-Control-Allow-Credentials'] = 'true' - headers['Access-Control-Expose-Headers'] = 'Content-Length' - end + def cor_filter + headers['Access-Control-Allow-Origin'] = request.headers['Origin'] ? + request.headers['Origin'] : + '' + headers['Access-Control-Allow-Credentials'] = 'true' + headers['Access-Control-Expose-Headers'] = 'Content-Length' + end - def cor_preflight - headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE' - headers['Access-Control-Allow-Headers'] = - 'Content-Type, Content-Length, X-Requested-With' + def cor_preflight + headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE' + headers['Access-Control-Allow-Headers'] = + 'Content-Type, Content-Length, X-Requested-With' - head :ok - end + head :ok + end - def authenticate! - head :unauthorized if current_user.nil? + def authenticate! + head :unauthorized if current_user.nil? + end end end diff --git a/app/controllers/api/playlists_controller.rb b/app/controllers/api/playlists_controller.rb index bbdc3c7..82997a5 100644 --- a/app/controllers/api/playlists_controller.rb +++ b/app/controllers/api/playlists_controller.rb @@ -1,12 +1,14 @@ -class API::PlaylistsController < API::ApplicationController - respond_to :json +module API + class PlaylistsController < ApplicationController + respond_to :json - def index - @playlists = Playlist.all - end + def index + @playlists = Playlist.all + end - def create - @playlist = current_user.playlists.build(params[:playlist].slice(:name)) - @playlist.save + def create + @playlist = current_user.playlists.build(params[:playlist].slice(:name)) + @playlist.save + end end end diff --git a/app/controllers/api/sessions_controller.rb b/app/controllers/api/sessions_controller.rb index 02b0db1..eaad78a 100644 --- a/app/controllers/api/sessions_controller.rb +++ b/app/controllers/api/sessions_controller.rb @@ -1,14 +1,16 @@ -class API::SessionsController < API::ApplicationController - skip_before_filter :authenticate!, only: [:create] +module API + class SessionsController < ApplicationController + skip_before_filter :authenticate!, only: [:create] - def create - user = User.find_by_email(params[:session][:email]) + def create + user = User.find_by_email(params[:session][:email]) - if !user.try(:authenticate?, params[:session][:password]) - return render json: '', status: :not_found + unless user.try(:authenticate?, params[:session][:password]) + return render json: '', status: :not_found + end + + @user = user + self.current_user = @user end - - @user = user - self.current_user = @user end end diff --git a/app/controllers/api/sounds_controller.rb b/app/controllers/api/sounds_controller.rb index 041c081..b5f3321 100644 --- a/app/controllers/api/sounds_controller.rb +++ b/app/controllers/api/sounds_controller.rb @@ -1,7 +1,9 @@ -class API::SoundsController < API::ApplicationController - # FIXME: add some tests! - def show - sound = Sound.find params[:id] - send_file sound.path, type: sound.mime_type +module API + class SoundsController < ApplicationController + # FIXME: add some tests! + def show + sound = Sound.find params[:id] + send_file sound.path, type: sound.mime_type + end end end diff --git a/app/controllers/api/tracks_controller.rb b/app/controllers/api/tracks_controller.rb index e78b390..427d4fa 100644 --- a/app/controllers/api/tracks_controller.rb +++ b/app/controllers/api/tracks_controller.rb @@ -1,5 +1,7 @@ -class API::TracksController < API::ApplicationController - def index - @tracks = Track.all +module API + class TracksController < ApplicationController + def index + @tracks = Track.all + end end end