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,15 +1,17 @@
class Admin::AdminController < ApplicationController module Admin
layout 'admin/layouts/admin' class AdminController < ApplicationController
before_filter :authenticate_admin_user! layout 'admin/layouts/admin'
before_filter :admin_menu 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 def admin_menu
@admin_menu = { dashboard: '', @admin_menu = { dashboard: '',
admin_users: '', admin_users: '',
categories: '', categories: '',
photos: '', photos: '',
pages: '' } pages: '' }
end
end end
end end

View File

@ -1,66 +1,64 @@
class Admin::AdminUsersController < Admin::AdminController module Admin
class AdminUsersController < Admin::AdminController
def index def index
@admin_users = AdminUser.all @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
end end
end
def create def new
@admin_user = AdminUser.new(permitted_params) @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 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])
@admin_user.destroy @admin_user.destroy
redirect_to admin_admin_users_path, notice: 'Admin User was deleted.' redirect_to admin_admin_users_path, notice: 'Admin User was deleted.'
end end
# Allow the current logged in user to change their password # Allow the current logged in user to change their password
def edit_password def edit_password
@admin_user = current_admin_user @admin_user = current_admin_user
end end
def update_password def update_password
@admin_user = current_admin_user @admin_user = current_admin_user
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
private
def permitted_params
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
end end
end end
private
def permitted_params
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
end
end end

View File

@ -1,48 +1,48 @@
class Admin::CategoriesController < Admin::AdminController module Admin
class CategoriesController < Admin::AdminController
def index def index
@categories = Category.all @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
end end
end
def create def new
@category = Category.new(permitted_params) @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 if @category.save
redirect_to admin_categories_path, notice: 'Category was successfully added.' redirect_to admin_categories_path, notice: 'Category was successfully added.'
else else
render :edit render :edit
end 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 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 end

View File

@ -1,60 +1,64 @@
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 end
else
self.class.add_error_on(self, :email, :password_allready_set)
end end
render_with_scope :new unless confirmable.errors.empty?
end end
if !@confirmable.errors.empty? def show
render_with_scope :new with_unconfirmed_confirmable do
end if @confirmable.has_no_password?
end do_show
else
do_confirm
end
end
def show render_with_scope :new unless @confirmable.errors.empty?
with_unconfirmed_confirmable do end
if @confirmable.has_no_password?
do_show private
else
def update_password
@confirmable.attempt_set_password(params[:admin_user])
if @confirmable.valid?
do_confirm do_confirm
else
do_show
@confirmable.errors.clear # so that we won't render :new
end end
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
end
protected def do_show
@confirmation_token = params[:confirmation_token]
def with_unconfirmed_confirmable @requires_password = true
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token]) self.resource = @confirmable
if !@confirmable.new_record? render_with_scope :show
@confirmable.only_if_unconfirmed {yield}
end end
end
def do_show def do_confirm
@confirmation_token = params[:confirmation_token] @confirmable.confirm!
@requires_password = true set_flash_message :notice, :confirmed
self.resource = @confirmable sign_in_and_redirect(resource_name, @confirmable)
render_with_scope :show end
end
def do_confirm
@confirmable.confirm!
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, @confirmable)
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,53 +1,53 @@
class Admin::PagesController < Admin::AdminController module Admin
class PagesController < Admin::AdminController
def index
@pages = Page.all
end
def index def new
@pages = Page.all @page = Page.new
end end
def new def edit
@page = Page.new @page = Page.find(params[:id])
end end
def edit def show
@page = Page.find(params[:id]) page = Page.find(params[:id])
end @page = PagePresenter.new(page)
end
def show def update
page = Page.find(params[:id]) @page = Page.find(params[:id])
@page = PagePresenter.new(page)
end
def update if @page.update_attributes(permitted_params)
@page = Page.find(params[:id]) redirect_to admin_pages_path, notice: 'Page was successfully updated.'
else
render :edit
end
end
if @page.update_attributes(permitted_params) def create
redirect_to admin_pages_path, notice: 'Page was successfully updated.' @page = Page.new(permitted_params)
else
render :edit 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
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 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,53 +1,55 @@
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)
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
end end
end
def create def new
@photo = Photo.new(permitted_params) @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 if @photo.save
redirect_to admin_photos_path, notice: 'Photo was successfully added.' redirect_to admin_photos_path, notice: 'Photo was successfully added.'
else else
render :edit render :edit
end 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 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 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,12 +1,14 @@
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
private private
def check_https def check_https
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
field_set_tag nil, class: :inputs, &block def inputs_field_set(&block)
end field_set_tag nil, class: :inputs, &block
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'