1
0
mirror of https://github.com/danbee/danbarberphoto synced 2025-03-04 08:49:07 +00:00

More Rubocop

This commit is contained in:
Daniel Barber 2015-09-16 22:11:35 +01:00
parent 318c99202e
commit dd64614fff
34 changed files with 282 additions and 319 deletions

View File

@ -1,5 +1,5 @@
Metrics/LineLength: Metrics/LineLength:
Max: 99 Max: 120
Documentation: Documentation:
Enabled: false Enabled: false

View File

@ -1,4 +1,5 @@
class Admin::AdminController < ApplicationController module Admin
class AdminController < ApplicationController
layout 'admin/layouts/admin' layout 'admin/layouts/admin'
before_filter :authenticate_admin_user! before_filter :authenticate_admin_user!
before_filter :admin_menu before_filter :admin_menu
@ -12,4 +13,5 @@ class Admin::AdminController < ApplicationController
photos: '', photos: '',
pages: '' } pages: '' }
end end
end
end end

View File

@ -1,5 +1,5 @@
class Admin::AdminUsersController < Admin::AdminController module Admin
class AdminUsersController < Admin::AdminController
def index def index
@admin_users = AdminUser.all @admin_users = AdminUser.all
end end
@ -25,14 +25,12 @@ class Admin::AdminUsersController < Admin::AdminController
def create def create
@admin_user = AdminUser.new(permitted_params) @admin_user = AdminUser.new(permitted_params)
respond_to do |format|
if @admin_user.save if @admin_user.save
redirect_to admin_admin_users_path, notice: 'Admin User was successfully added.' redirect_to admin_admin_users_path, notice: 'Admin User was successfully added.'
else else
render :edit render :edit
end end
end end
end
def destroy def destroy
@admin_user = AdminUser.find(params[:id]) @admin_user = AdminUser.find(params[:id])
@ -51,7 +49,7 @@ class Admin::AdminUsersController < Admin::AdminController
if @admin_user.update_with_password(permitted_params) if @admin_user.update_with_password(permitted_params)
sign_in @admin_user, bypass: true sign_in @admin_user, bypass: true
redirect_to admin_dashboard_path, notice: "Password updated!" redirect_to admin_dashboard_path, notice: 'Password updated!'
else else
render :edit_password render :edit_password
end end
@ -62,5 +60,5 @@ class Admin::AdminUsersController < Admin::AdminController
def permitted_params def permitted_params
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me) params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
end end
end
end end

View File

@ -1,5 +1,5 @@
class Admin::CategoriesController < Admin::AdminController module Admin
class CategoriesController < Admin::AdminController
def index def index
@categories = Category.all @categories = Category.all
end end
@ -44,5 +44,5 @@ class Admin::CategoriesController < Admin::AdminController
def permitted_params def permitted_params
params.require(:category).permit(:name, :slug, :description, :base_colour, :sort) params.require(:category).permit(:name, :slug, :description, :base_colour, :sort)
end end
end
end end

View File

@ -1,26 +1,19 @@
class Admin::ConfirmationsController < ::Devise::PasswordsController module Admin
layout "admin/layouts/login" class ConfirmationsController < ::Devise::PasswordsController
layout 'admin/layouts/login'
skip_before_filter(:authenticate_user!) skip_before_filter(:authenticate_user!)
def update def update
with_unconfirmed_confirmable do with_unconfirmed_confirmable do
if @confirmable.has_no_password? if @confirmable.has_no_password?
@confirmable.attempt_set_password(params[:admin_user]) update_password
if @confirmable.valid?
do_confirm
else else
do_show self.class.add_error_on(self, :email, :password_already_set)
@confirmable.errors.clear #so that we wont render :new
end
else
self.class.add_error_on(self, :email, :password_allready_set)
end end
end end
if !@confirmable.errors.empty? render_with_scope :new unless confirmable.errors.empty?
render_with_scope :new
end
end end
def show def show
@ -31,8 +24,19 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
do_confirm do_confirm
end end
end end
if !@confirmable.errors.empty?
render_with_scope :new render_with_scope :new unless @confirmable.errors.empty?
end
private
def update_password
@confirmable.attempt_set_password(params[:admin_user])
if @confirmable.valid?
do_confirm
else
do_show
@confirmable.errors.clear # so that we won't render :new
end end
end end
@ -40,9 +44,8 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
def with_unconfirmed_confirmable def with_unconfirmed_confirmable
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token]) @confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
if !@confirmable.new_record?
@confirmable.only_if_unconfirmed {yield} @confirmable.only_if_unconfirmed { yield } unless @confirmable.new_record?
end
end end
def do_show def do_show
@ -57,4 +60,5 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
set_flash_message :notice, :confirmed set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, @confirmable) sign_in_and_redirect(resource_name, @confirmable)
end end
end
end end

View File

@ -1,2 +1,4 @@
class Admin::DashboardController < Admin::AdminController module Admin
class DashboardController < Admin::AdminController
end
end end

View File

@ -1,5 +1,5 @@
class Admin::PagesController < Admin::AdminController module Admin
class PagesController < Admin::AdminController
def index def index
@pages = Page.all @pages = Page.all
end end
@ -49,5 +49,5 @@ class Admin::PagesController < Admin::AdminController
def permitted_params def permitted_params
params.require(:page).permit(:name, :title, :content) params.require(:page).permit(:name, :title, :content)
end end
end
end end

View File

@ -1,3 +1,5 @@
class Admin::PasswordsController < ::Devise::PasswordsController module Admin
layout "admin/layouts/login" class PasswordsController < ::Devise::PasswordsController
layout 'admin/layouts/login'
end
end end

View File

@ -1,5 +1,6 @@
class Admin::PhotosController < Admin::AdminController module Admin
before_filter :get_categories class PhotosController < Admin::AdminController
before_filter :categories
def index def index
@photos = Photo.paginate(page: params[:page], per_page: 16) @photos = Photo.paginate(page: params[:page], per_page: 16)
@ -42,12 +43,13 @@ class Admin::PhotosController < Admin::AdminController
private private
def get_categories def categories
@categories = Category.all @categories = Category.all
end end
def permitted_params def permitted_params
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured, :enabled, :taken_at, category_ids: []) params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured,
:enabled, :taken_at, category_ids: [])
end
end end
end end

View File

@ -1,3 +1,5 @@
class Admin::RegistrationsController < ::Devise::RegistrationsController module Admin
layout "admin/layouts/login" class RegistrationsController < ::Devise::RegistrationsController
layout 'admin/layouts/login'
end
end end

View File

@ -1,5 +1,6 @@
class Admin::SessionsController < ::Devise::SessionsController module Admin
layout "admin/layouts/login" class SessionsController < ::Devise::SessionsController
layout 'admin/layouts/login'
before_filter :check_https before_filter :check_https
@ -9,4 +10,5 @@ class Admin::SessionsController < ::Devise::SessionsController
secure_link = url_for(protocol: 'https') secure_link = url_for(protocol: 'https')
flash[:alert] = I18n.t('insecure_alert', secure_link: secure_link).html_safe unless request.scheme == 'https' flash[:alert] = I18n.t('insecure_alert', secure_link: secure_link).html_safe unless request.scheme == 'https'
end end
end
end end

View File

@ -1,3 +1,5 @@
class Admin::UnlocksController < ::Devise::UnlocksController module Admin
layout "admin/layouts/login" class UnlocksController < ::Devise::UnlocksController
layout 'admin/layouts/login'
end
end end

View File

@ -1,9 +1,11 @@
module Admin::AdminHelper module Admin
def inputs_field_set &block module AdminHelper
def inputs_field_set(&block)
field_set_tag nil, class: :inputs, &block field_set_tag nil, class: :inputs, &block
end end
def actions_field_set &block def actions_field_set(&block)
field_set_tag nil, class: :actions, &block field_set_tag nil, class: :actions, &block
end end
end
end end

View File

@ -1,2 +0,0 @@
module Admin::DashboardHelper
end

View File

@ -1,2 +0,0 @@
module Admin::DownloadsHelper
end

View File

@ -1,2 +0,0 @@
module Admin::UnlocksHelper
end

View File

@ -3,8 +3,6 @@ class Notifier < ActionMailer::Base
def contact_notification(sender) def contact_notification(sender)
@sender = sender @sender = sender
mail( to: 'enquiries@danbarberphoto.com', mail(to: 'enquiries@danbarberphoto.com', from: sender.email, subject: sender.subject)
from: sender.email,
subject: sender.subject)
end end
end end

View File

@ -5,11 +5,7 @@ class Heartbeat
def call(env) def call(env)
if env['PATH_INFO'] == '/heartbeat' if env['PATH_INFO'] == '/heartbeat'
[ [200, { 'Content-Type' => 'text/plain' }, ['OK']]
200,
{"Content-Type" => "text/plain"},
["OK"]
]
else else
@app.call(env) @app.call(env)
end end

View File

@ -10,8 +10,8 @@ class AdminUser < ActiveRecord::Base
end end
# new function to return whether a password has been set # new function to return whether a password has been set
def has_no_password? def no_password?
self.encrypted_password.blank? encrypted_password.blank?
end end
# new function to provide access to protected method unless_confirmed # new function to provide access to protected method unless_confirmed

View File

@ -9,12 +9,12 @@ class Contact
def initialize(attributes = {}) def initialize(attributes = {})
attributes.each do |key, value| attributes.each do |key, value|
self.send("#{key}=", value) send("#{key}=", value)
end end
end end
def read_attribute_for_validation(key) def read_attribute_for_validation(key)
self.send(key) send(key)
end end
def save def save
@ -22,7 +22,6 @@ class Contact
Notifier.contact_notification(self).deliver Notifier.contact_notification(self).deliver
return true return true
end end
return false false
end end
end end

View File

@ -1,5 +1,4 @@
class Photo < ActiveRecord::Base class Photo < ActiveRecord::Base
has_and_belongs_to_many :categories has_and_belongs_to_many :categories
dragonfly_accessor :image dragonfly_accessor :image
@ -8,25 +7,24 @@ class Photo < ActiveRecord::Base
@@per_page = 11 @@per_page = 11
scope :enabled, lambda { where(enabled: true) } scope :enabled, -> { where(enabled: true) }
scope :featured, lambda { enabled.where(featured: true) } scope :featured, -> { enabled.where(featured: true) }
def to_s def to_s
self.title title
end end
def name def name
self.title title
end end
def log_view def log_view
if self.views.nil? if views.nil?
self.views = 1 self.views = 1
else else
self.views += 1 self.views += 1
end end
self.save save
end end
end end

View File

@ -4,6 +4,6 @@ class PagePresenter < SimpleDelegator
end end
def self.markdown def self.markdown
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {}) @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions: {})
end end
end end

View File

@ -1,10 +1,7 @@
# lib/email_validator.rb # lib/email_validator.rb
class EmailValidator < ActiveModel::EachValidator class EmailValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value) def validate_each(object, attribute, value)
unless value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i return if value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
object.errors[attribute] << (options[:message] || "is not valid") object.errors[attribute] << (options[:message] || 'is not valid')
end end
end
end end

View File

@ -1,4 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'

View File

@ -1,6 +0,0 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'