Fix some rubocop issues

This commit is contained in:
luisramos0
2019-11-11 21:31:07 +00:00
parent 8cfd7c610b
commit f79182253a

View File

@@ -4,25 +4,25 @@ module Spree
module Admin
class ResourceController < Spree::Admin::BaseController
helper_method :new_object_url, :edit_object_url, :object_url, :collection_url
before_filter :load_resource, :except => [:update_positions]
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
rescue_from CanCan::AccessDenied, :with => :unauthorized
before_filter :load_resource, except: [:update_positions]
rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found
rescue_from CanCan::AccessDenied, with: :unauthorized
respond_to :html
respond_to :js, :except => [:show, :index]
respond_to :js, except: [:show, :index]
def new
invoke_callbacks(:new_action, :before)
respond_with(@object) do |format|
format.html { render :layout => !request.xhr? }
format.js { render :layout => false }
format.html { render layout: !request.xhr? }
format.js { render layout: false }
end
end
def edit
respond_with(@object) do |format|
format.html { render :layout => !request.xhr? }
format.js { render :layout => false }
format.html { render layout: !request.xhr? }
format.js { render layout: false }
end
end
@@ -33,7 +33,7 @@ module Spree
flash[:success] = flash_message_for(@object, :successfully_updated)
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render :layout => false }
format.js { render layout: false }
end
else
invoke_callbacks(:update, :fails)
@@ -49,7 +49,7 @@ module Spree
flash[:success] = flash_message_for(@object, :successfully_created)
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render :layout => false }
format.js { render layout: false }
end
else
invoke_callbacks(:create, :fails)
@@ -59,11 +59,11 @@ module Spree
def update_positions
params[:positions].each do |id, index|
model_class.where(:id => id).update_all(:position => index)
model_class.where(id: id).update_all(position: index)
end
respond_to do |format|
format.js { render :text => 'Ok' }
format.js { render text: 'Ok' }
end
end
@@ -74,7 +74,7 @@ module Spree
flash[:success] = flash_message_for(@object, :successfully_removed)
respond_with(@object) do |format|
format.html { redirect_to collection_url }
format.js { render :partial => "spree/admin/shared/destroy" }
format.js { render partial: "spree/admin/shared/destroy" }
end
else
invoke_callbacks(:destroy, :fails)
@@ -175,17 +175,16 @@ module Spree
end
def parent
if parent_data.present?
@parent ||= parent_data[:model_class].send("find_by_#{parent_data[:find_by]}", params["#{model_name}_id"])
instance_variable_set("@#{model_name}", @parent)
else
nil
end
return nil if parent_data.blank?
@parent ||= parent_data[:model_class].
public_send("find_by_#{parent_data[:find_by]}", params["#{model_name}_id"])
instance_variable_set("@#{model_name}", @parent)
end
def find_resource
if parent_data.present?
parent.send(controller_name).find(params[:id])
parent.public_send(controller_name).find(params[:id])
else
model_class.find(params[:id])
end
@@ -193,15 +192,17 @@ module Spree
def build_resource
if parent_data.present?
parent.send(controller_name).build
parent.public_send(controller_name).build
else
model_class.new
end
end
def collection
return parent.send(controller_name) if parent_data.present?
if model_class.respond_to?(:accessible_by) && !current_ability.has_block?(params[:action], model_class)
return parent.public_send(controller_name) if parent_data.present?
if model_class.respond_to?(:accessible_by) &&
!current_ability.has_block?(params[:action], model_class)
model_class.accessible_by(current_ability, action)
else
model_class.scoped
@@ -215,10 +216,11 @@ module Spree
def invoke_callbacks(action, callback_type)
callbacks = self.class.callbacks || {}
return if callbacks[action].nil?
case callback_type.to_sym
when :before then callbacks[action].before_methods.each {|method| send method }
when :after then callbacks[action].after_methods.each {|method| send method }
when :fails then callbacks[action].fails_methods.each {|method| send method }
when :before then callbacks[action].before_methods.each { |method| __send__ method }
when :after then callbacks[action].after_methods.each { |method| __send__ method }
when :fails then callbacks[action].fails_methods.each { |method| __send__ method }
end
end
@@ -234,18 +236,18 @@ module Spree
def edit_object_url(object, options = {})
if parent_data.present?
spree.send "edit_admin_#{model_name}_#{object_name}_url", parent, object, options
spree.public_send "edit_admin_#{model_name}_#{object_name}_url", parent, object, options
else
spree.send "edit_admin_#{object_name}_url", object, options
spree.public_send "edit_admin_#{object_name}_url", object, options
end
end
def object_url(object = nil, options = {})
target = object ? object : @object
target = object || @object
if parent_data.present?
spree.send "admin_#{model_name}_#{object_name}_url", parent, target, options
spree.public_send "admin_#{model_name}_#{object_name}_url", parent, target, options
else
spree.send "admin_#{object_name}_url", target, options
spree.public_send "admin_#{object_name}_url", target, options
end
end