Fix coding standards in application files
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
				
			|||||||
module API
 | 
					module API
 | 
				
			||||||
  class ApplicationController < ::ApplicationController
 | 
					  class ApplicationController < ::ApplicationController
 | 
				
			||||||
    skip_before_filter :verify_authenticity_token
 | 
					    skip_before_filter :verify_authenticity_token
 | 
				
			||||||
    skip_before_filter :authenticate!, only: [:cor_preflight]
 | 
					    skip_before_filter :authenticate!, only: :cor_preflight
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    before_filter :cor_filter
 | 
					    before_filter :cor_filter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,14 +5,15 @@ module API
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create
 | 
					    def create
 | 
				
			||||||
      @playlist = current_user.playlists.build(playlist_params)
 | 
					      @playlist = current_user.playlists.build playlist_params
 | 
				
			||||||
      @playlist.save
 | 
					      @playlist.save
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private
 | 
					    private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def playlist_params
 | 
					    def playlist_params
 | 
				
			||||||
      params.require(:playlist).permit(:name)
 | 
					      params.require(:playlist).permit :name
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +1,11 @@
 | 
				
			|||||||
module API
 | 
					module API
 | 
				
			||||||
  class SessionsController < ApplicationController
 | 
					  class SessionsController < ApplicationController
 | 
				
			||||||
    skip_before_filter :authenticate!, only: [:create]
 | 
					    skip_before_filter :authenticate!, only: :create
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create
 | 
					    def create
 | 
				
			||||||
      user = User.find_by_email(params[:session][:email])
 | 
					      user = User.find_by_email(params[:session][:email])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      unless user.try(:authenticate?, params[:session][:password])
 | 
					      unless user.try :authenticate?, params[:session][:password]
 | 
				
			||||||
        return render json: '', status: :not_found
 | 
					        return render json: '', status: :not_found
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@ module API
 | 
				
			|||||||
  class SoundsController < ApplicationController
 | 
					  class SoundsController < ApplicationController
 | 
				
			||||||
    # FIXME: add some tests!
 | 
					    # FIXME: add some tests!
 | 
				
			||||||
    def show
 | 
					    def show
 | 
				
			||||||
      sound = Sound.find params[:id]
 | 
					      sound = Sound.find(params[:id])
 | 
				
			||||||
      send_file sound.path, type: sound.mime_type
 | 
					      send_file sound.path, type: sound.mime_type
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  before_filter :authenticate!
 | 
					  before_filter :authenticate!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def current_user=(user)
 | 
					  def current_user= user
 | 
				
			||||||
    session[:user_id] = user.id
 | 
					    session[:user_id] = user.id
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
 | 
				
			|||||||
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
 | 
					    @current_user ||= User.find(session[:user_id]) if session[:user_id]
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  protected
 | 
					  protected
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def authenticate!
 | 
					  def authenticate!
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,8 @@ class PlaylistsController < ApplicationController
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def create
 | 
					  def create
 | 
				
			||||||
    @playlist = current_user.playlists.build(playlist_params)
 | 
					    @playlist = current_user.playlists.build playlist_params
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if @playlist.save
 | 
					    if @playlist.save
 | 
				
			||||||
      redirect_to action: 'index'
 | 
					      redirect_to action: 'index'
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
@@ -22,6 +23,7 @@ class PlaylistsController < ApplicationController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def update
 | 
					  def update
 | 
				
			||||||
    @playlist = Playlist.find(params[:id])
 | 
					    @playlist = Playlist.find(params[:id])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if @playlist.update_attributes playlist_params
 | 
					    if @playlist.update_attributes playlist_params
 | 
				
			||||||
      redirect_to action: 'index'
 | 
					      redirect_to action: 'index'
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
@@ -29,9 +31,10 @@ class PlaylistsController < ApplicationController
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private
 | 
					  private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def playlist_params
 | 
					  def playlist_params
 | 
				
			||||||
    params.require(:playlist).permit(:name)
 | 
					    params.require(:playlist).permit :name
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,10 @@
 | 
				
			|||||||
class SessionsController < ApplicationController
 | 
					class SessionsController < ApplicationController
 | 
				
			||||||
  skip_before_filter :authenticate!, only: [:new, :create]
 | 
					  skip_before_filter :authenticate!, only: %i[new create]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def create
 | 
					  def create
 | 
				
			||||||
    user = User.find_by_email(params[:session][:email])
 | 
					    user = User.find_by_email(params[:session][:email])
 | 
				
			||||||
    if user.try(:authenticate?, params[:session][:password])
 | 
					
 | 
				
			||||||
 | 
					    if user.try :authenticate?, params[:session][:password]
 | 
				
			||||||
      self.current_user = user
 | 
					      self.current_user = user
 | 
				
			||||||
      redirect_to :root
 | 
					      redirect_to :root
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
class SoundsController < ApplicationController
 | 
					class SoundsController < ApplicationController
 | 
				
			||||||
  def show
 | 
					  def show
 | 
				
			||||||
    sound = Sound.find params[:id]
 | 
					    sound = Sound.find(params[:id])
 | 
				
			||||||
    send_file sound.path, type: sound.mime_type
 | 
					    send_file sound.path, type: sound.mime_type
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
class TracksController < ApplicationController
 | 
					class TracksController < ApplicationController
 | 
				
			||||||
  def show
 | 
					  def show
 | 
				
			||||||
    @track = Track.find params[:id]
 | 
					    @track = Track.find(params[:id])
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def new
 | 
					  def new
 | 
				
			||||||
@@ -8,7 +8,8 @@ class TracksController < ApplicationController
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def create
 | 
					  def create
 | 
				
			||||||
    @track = Track.new track_params
 | 
					    @track = Track.new(track_params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if @track.save
 | 
					    if @track.save
 | 
				
			||||||
      redirect_to @track
 | 
					      redirect_to @track
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
@@ -19,6 +20,6 @@ class TracksController < ApplicationController
 | 
				
			|||||||
  private
 | 
					  private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def track_params
 | 
					  def track_params
 | 
				
			||||||
    params.require(:track).permit(:name, :file)
 | 
					    params.require(:track).permit %i[name file]
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
class UsersController < ApplicationController
 | 
					class UsersController < ApplicationController
 | 
				
			||||||
  skip_before_filter :authenticate!, only: [:new, :create]
 | 
					  skip_before_filter :authenticate!, only: %i[new create]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def new
 | 
					  def new
 | 
				
			||||||
    @user = User.new
 | 
					    @user = User.new
 | 
				
			||||||
@@ -7,6 +7,7 @@ class UsersController < ApplicationController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def create
 | 
					  def create
 | 
				
			||||||
    @user = User.new(user_params)
 | 
					    @user = User.new(user_params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if !@user.save
 | 
					    if !@user.save
 | 
				
			||||||
      render :new
 | 
					      render :new
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
@@ -18,6 +19,6 @@ class UsersController < ApplicationController
 | 
				
			|||||||
  private
 | 
					  private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def user_params
 | 
					  def user_params
 | 
				
			||||||
    params.require(:user).permit(:email, :password, :password_confirmation)
 | 
					    params.require(:user).permit %i[email password password_confirmation]
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ class Sound < ActiveRecord::Base
 | 
				
			|||||||
    "#{Rails.configuration.sounds_path}/#{sha256}"
 | 
					    "#{Rails.configuration.sounds_path}/#{sha256}"
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def file=(file)
 | 
					  def file= file
 | 
				
			||||||
    self.sha256 = Digest::SHA256.file(file.path).hexdigest
 | 
					    self.sha256 = Digest::SHA256.file(file.path).hexdigest
 | 
				
			||||||
    FileUtils.cp file.path, path
 | 
					    FileUtils.cp file.path, path
 | 
				
			||||||
    self.mime_type = file.content_type
 | 
					    self.mime_type = file.content_type
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,8 @@ class Track < ActiveRecord::Base
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  validates_presence_of :name
 | 
					  validates_presence_of :name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def file=(file)
 | 
					  def file= file
 | 
				
			||||||
    sounds.build(file: file)
 | 
					    sounds.build file: file
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def sound
 | 
					  def sound
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,12 +15,12 @@ class User < ActiveRecord::Base
 | 
				
			|||||||
    confirmation: true
 | 
					    confirmation: true
 | 
				
			||||||
  validates_presence_of :password_hash
 | 
					  validates_presence_of :password_hash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def password=(plain_password)
 | 
					  def password= plain_password
 | 
				
			||||||
    @password = plain_password
 | 
					    @password = plain_password
 | 
				
			||||||
    self.password_hash = Password.create(plain_password)
 | 
					    self.password_hash = Password.create(plain_password)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def authenticate?(password)
 | 
					  def authenticate? password
 | 
				
			||||||
    Password.new(password_hash) == password
 | 
					    Password.new(password_hash) == password
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
= form_for(:session, url: sessions_path) do |f|
 | 
					= form_for :session, url: sessions_path do |f|
 | 
				
			||||||
  %table
 | 
					  %table
 | 
				
			||||||
    %tbody
 | 
					    %tbody
 | 
				
			||||||
      %tr
 | 
					      %tr
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
= form_for(@user, url: users_path) do |f|
 | 
					= form_for @user, url: users_path do |f|
 | 
				
			||||||
  - if @user.errors.any?
 | 
					  - if @user.errors.any?
 | 
				
			||||||
    %ul
 | 
					    %ul
 | 
				
			||||||
      - @user.errors.full_messages.each do |m|
 | 
					      - @user.errors.full_messages.each do |m|
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user