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:
Max: 99
Max: 120
Documentation:
Enabled: false

View File

@ -1,15 +1,17 @@
class Admin::AdminController < ApplicationController
layout 'admin/layouts/admin'
before_filter :authenticate_admin_user!
before_filter :admin_menu
module Admin
class AdminController < ApplicationController
layout 'admin/layouts/admin'
before_filter :authenticate_admin_user!
before_filter :admin_menu
force_ssl host: APP_CONFIG[:ssl_hostname]
force_ssl host: APP_CONFIG[:ssl_hostname]
def admin_menu
@admin_menu = { dashboard: '',
admin_users: '',
categories: '',
photos: '',
pages: '' }
def admin_menu
@admin_menu = { dashboard: '',
admin_users: '',
categories: '',
photos: '',
pages: '' }
end
end
end

View File

@ -1,66 +1,64 @@
class Admin::AdminUsersController < Admin::AdminController
def index
@admin_users = AdminUser.all
end
def new
@admin_user = AdminUser.new
end
def edit
@admin_user = AdminUser.find(params[:id])
end
def update
@admin_user = AdminUser.find(params[:id])
if @admin_user.update_attributes(permitted_params)
redirect_to admin_admin_users_path, notice: 'Admin User was successfully updated.'
else
render :edit
module Admin
class AdminUsersController < Admin::AdminController
def index
@admin_users = AdminUser.all
end
end
def create
@admin_user = AdminUser.new(permitted_params)
def new
@admin_user = AdminUser.new
end
def edit
@admin_user = AdminUser.find(params[:id])
end
def update
@admin_user = AdminUser.find(params[:id])
if @admin_user.update_attributes(permitted_params)
redirect_to admin_admin_users_path, notice: 'Admin User was successfully updated.'
else
render :edit
end
end
def create
@admin_user = AdminUser.new(permitted_params)
respond_to do |format|
if @admin_user.save
redirect_to admin_admin_users_path, notice: 'Admin User was successfully added.'
else
render :edit
end
end
end
def destroy
@admin_user = AdminUser.find(params[:id])
@admin_user.destroy
def destroy
@admin_user = AdminUser.find(params[:id])
@admin_user.destroy
redirect_to admin_admin_users_path, notice: 'Admin User was deleted.'
end
redirect_to admin_admin_users_path, notice: 'Admin User was deleted.'
end
# Allow the current logged in user to change their password
def edit_password
@admin_user = current_admin_user
end
# Allow the current logged in user to change their password
def edit_password
@admin_user = current_admin_user
end
def update_password
@admin_user = current_admin_user
def update_password
@admin_user = current_admin_user
if @admin_user.update_with_password(permitted_params)
sign_in @admin_user, bypass: true
redirect_to admin_dashboard_path, notice: "Password updated!"
else
render :edit_password
if @admin_user.update_with_password(permitted_params)
sign_in @admin_user, bypass: true
redirect_to admin_dashboard_path, notice: 'Password updated!'
else
render :edit_password
end
end
private
def permitted_params
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
end
end
private
def permitted_params
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
end
end

View File

@ -1,48 +1,48 @@
class Admin::CategoriesController < Admin::AdminController
def index
@categories = Category.all
end
def new
@category = Category.new
end
def edit
@category = Category.find(params[:id])
end
def update
@category = Category.find(params[:id])
if @category.update_attributes(permitted_params)
redirect_to admin_categories_path, notice: 'Category was successfully updated.'
else
render :edit
module Admin
class CategoriesController < Admin::AdminController
def index
@categories = Category.all
end
end
def create
@category = Category.new(permitted_params)
def new
@category = Category.new
end
def edit
@category = Category.find(params[:id])
end
def update
@category = Category.find(params[:id])
if @category.update_attributes(permitted_params)
redirect_to admin_categories_path, notice: 'Category was successfully updated.'
else
render :edit
end
end
def create
@category = Category.new(permitted_params)
if @category.save
redirect_to admin_categories_path, notice: 'Category was successfully added.'
else
render :edit
end
end
def destroy
@category = Category.find(params[:id])
@category.destroy
redirect_to admin_categories_path, notice: 'Category was deleted.'
end
private
def permitted_params
params.require(:category).permit(:name, :slug, :description, :base_colour, :sort)
end
end
def destroy
@category = Category.find(params[:id])
@category.destroy
redirect_to admin_categories_path, notice: 'Category was deleted.'
end
private
def permitted_params
params.require(:category).permit(:name, :slug, :description, :base_colour, :sort)
end
end

View File

@ -1,60 +1,64 @@
class Admin::ConfirmationsController < ::Devise::PasswordsController
layout "admin/layouts/login"
module Admin
class ConfirmationsController < ::Devise::PasswordsController
layout 'admin/layouts/login'
skip_before_filter(:authenticate_user!)
skip_before_filter(:authenticate_user!)
def update
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
@confirmable.attempt_set_password(params[:admin_user])
if @confirmable.valid?
do_confirm
def update
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
update_password
else
do_show
@confirmable.errors.clear #so that we wont render :new
self.class.add_error_on(self, :email, :password_already_set)
end
else
self.class.add_error_on(self, :email, :password_allready_set)
end
render_with_scope :new unless confirmable.errors.empty?
end
if !@confirmable.errors.empty?
render_with_scope :new
end
end
def show
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
do_show
else
do_confirm
end
end
def show
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
do_show
else
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
if !@confirmable.errors.empty?
render_with_scope :new
protected
def with_unconfirmed_confirmable
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
@confirmable.only_if_unconfirmed { yield } unless @confirmable.new_record?
end
end
protected
def with_unconfirmed_confirmable
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
if !@confirmable.new_record?
@confirmable.only_if_unconfirmed {yield}
def do_show
@confirmation_token = params[:confirmation_token]
@requires_password = true
self.resource = @confirmable
render_with_scope :show
end
end
def do_show
@confirmation_token = params[:confirmation_token]
@requires_password = true
self.resource = @confirmable
render_with_scope :show
end
def do_confirm
@confirmable.confirm!
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, @confirmable)
def do_confirm
@confirmable.confirm!
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, @confirmable)
end
end
end

View File

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

View File

@ -1,53 +1,53 @@
class Admin::PagesController < Admin::AdminController
module Admin
class PagesController < Admin::AdminController
def index
@pages = Page.all
end
def index
@pages = Page.all
end
def new
@page = Page.new
end
def new
@page = Page.new
end
def edit
@page = Page.find(params[:id])
end
def edit
@page = Page.find(params[:id])
end
def show
page = Page.find(params[:id])
@page = PagePresenter.new(page)
end
def show
page = Page.find(params[:id])
@page = PagePresenter.new(page)
end
def update
@page = Page.find(params[:id])
def update
@page = Page.find(params[:id])
if @page.update_attributes(permitted_params)
redirect_to admin_pages_path, notice: 'Page was successfully updated.'
else
render :edit
end
end
if @page.update_attributes(permitted_params)
redirect_to admin_pages_path, notice: 'Page was successfully updated.'
else
render :edit
def create
@page = Page.new(permitted_params)
if @page.save
redirect_to admin_pages_path, notice: 'Page was successfully added.'
else
render :edit
end
end
def destroy
@page = Page.find(params[:id])
@page.destroy
redirect_to admin_pages_path, notice: 'Page was deleted.'
end
private
def permitted_params
params.require(:page).permit(:name, :title, :content)
end
end
def create
@page = Page.new(permitted_params)
if @page.save
redirect_to admin_pages_path, notice: 'Page was successfully added.'
else
render :edit
end
end
def destroy
@page = Page.find(params[:id])
@page.destroy
redirect_to admin_pages_path, notice: 'Page was deleted.'
end
private
def permitted_params
params.require(:page).permit(:name, :title, :content)
end
end

View File

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

View File

@ -1,53 +1,55 @@
class Admin::PhotosController < Admin::AdminController
before_filter :get_categories
module Admin
class PhotosController < Admin::AdminController
before_filter :categories
def index
@photos = Photo.paginate(page: params[:page], per_page: 16)
end
def new
@photo = Photo.new
end
def edit
@photo = Photo.find(params[:id])
end
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(permitted_params)
redirect_to admin_photos_path, notice: 'Photo was successfully updated.'
else
render :edit
def index
@photos = Photo.paginate(page: params[:page], per_page: 16)
end
end
def create
@photo = Photo.new(permitted_params)
def new
@photo = Photo.new
end
def edit
@photo = Photo.find(params[:id])
end
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(permitted_params)
redirect_to admin_photos_path, notice: 'Photo was successfully updated.'
else
render :edit
end
end
def create
@photo = Photo.new(permitted_params)
if @photo.save
redirect_to admin_photos_path, notice: 'Photo was successfully added.'
else
render :edit
end
end
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
redirect_to :back, notice: 'Photo was deleted.'
end
private
def categories
@categories = Category.all
end
def permitted_params
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured,
:enabled, :taken_at, category_ids: [])
end
end
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
redirect_to :back, notice: 'Photo was deleted.'
end
private
def get_categories
@categories = Category.all
end
def permitted_params
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured, :enabled, :taken_at, category_ids: [])
end
end

View File

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

View File

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

View File

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

View File

@ -1,9 +1,11 @@
module Admin::AdminHelper
def inputs_field_set &block
field_set_tag nil, class: :inputs, &block
end
module Admin
module AdminHelper
def inputs_field_set(&block)
field_set_tag nil, class: :inputs, &block
end
def actions_field_set &block
field_set_tag nil, class: :actions, &block
def actions_field_set(&block)
field_set_tag nil, class: :actions, &block
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)
@sender = sender
mail( to: 'enquiries@danbarberphoto.com',
from: sender.email,
subject: sender.subject)
mail(to: 'enquiries@danbarberphoto.com', from: sender.email, subject: sender.subject)
end
end

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
class Photo < ActiveRecord::Base
has_and_belongs_to_many :categories
dragonfly_accessor :image
@ -8,25 +7,24 @@ class Photo < ActiveRecord::Base
@@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
self.title
title
end
def name
self.title
title
end
def log_view
if self.views.nil?
if views.nil?
self.views = 1
else
self.views += 1
end
self.save
save
end
end

View File

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

View File

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