Fix current violations of Style/Send cop

This commit is contained in:
Pau Perez
2018-08-31 12:10:52 +02:00
parent 1de13a5049
commit b23cb55525
35 changed files with 103 additions and 106 deletions

View File

@@ -14,7 +14,7 @@ module Admin
def update
params.each do |name, value|
if ContentConfig.has_preference?(name) || ContentConfig.has_attachment?(name)
ContentConfig.send("#{name}=", value)
ContentConfig.public_send("#{name}=", value)
end
end

View File

@@ -19,7 +19,7 @@ module Admin
# we can authorise #create using an object with required attributes
def build_resource
if parent_data.present?
parent.send(controller_name).build
parent.public_send(controller_name).build
else
model_class.new(params[object_name]) # This line changed
end

View File

@@ -53,7 +53,7 @@ module Admin
@importer = ProductImport::ProductImporter.new(File.new(params[:filepath]), spree_current_user, start: params[:start], end: params[:end], settings: params[:settings])
begin
@importer.send("#{method}_entries")
@importer.public_send("#{method}_entries")
rescue StandardError => e
render json: e.message, response: 500
return false

View File

@@ -15,18 +15,18 @@ module Admin
def edit_object_url(object, options = {})
if parent_data.present?
main_app.send "edit_admin_#{model_name}_#{object_name}_url", parent, object, options
main_app.public_send "edit_admin_#{model_name}_#{object_name}_url", parent, object, options
else
main_app.send "edit_admin_#{object_name}_url", object, options
main_app.public_send "edit_admin_#{object_name}_url", object, options
end
end
def object_url(object = nil, options = {})
target = object ? object : @object
if parent_data.present?
main_app.send "admin_#{model_name}_#{object_name}_url", parent, target, options
main_app.public_send "admin_#{model_name}_#{object_name}_url", parent, target, options
else
main_app.send "admin_#{object_name}_url", target, options
main_app.public_send "admin_#{object_name}_url", target, options
end
end

View File

@@ -77,7 +77,7 @@ class EnterprisesController < BaseController
def reset_user_and_customer(order)
order.associate_user!(spree_current_user) if order.user.blank? || order.email.blank?
order.send(:associate_customer) if order.customer.nil? # Only associates existing customers
order.__send__(:associate_customer) if order.customer.nil? # Only associates existing customers
end
def reset_order_cycle(order, distributor)

View File

@@ -44,7 +44,7 @@ class ShopController < BaseController
private
def filtered_json(products_json)
if applicator.send(:rules).any?
if applicator.rules.any?
filter(products_json)
else
products_json

View File

@@ -10,6 +10,6 @@ module Spree
@preferences_general << :bugherd_api_key
end
end
GeneralSettingsController.send(:prepend, GeneralSettingsEditPreferences)
GeneralSettingsController.prepend(GeneralSettingsEditPreferences)
end
end

View File

@@ -10,7 +10,7 @@ module Spree
# Only show payment methods that user has access to and sort by distributor name
# ! Redundant code copied from Spree::Admin::ResourceController with modifications marked
def collection
return parent.send(controller_name) if parent_data.present?
return parent.public_send(controller_name) if parent_data.present?
collection = if model_class.respond_to?(:accessible_by) &&
!current_ability.has_block?(params[:action], model_class)

View File

@@ -10,7 +10,7 @@ Spree::Admin::PaymentsController.class_eval do
# Because we have a transition method also called void, we do this to avoid conflicts.
event = "void_transaction" if event == "void"
if @payment.send("#{event}!")
if @payment.public_send("#{event}!")
flash[:success] = t(:payment_updated)
else
flash[:error] = t(:cannot_perform_operation)

View File

@@ -13,4 +13,4 @@ module AuthorizeOnLoadResource
end
end
Spree::Admin::ResourceController.send(:prepend, AuthorizeOnLoadResource)
Spree::Admin::ResourceController.prepend(AuthorizeOnLoadResource)

View File

@@ -7,7 +7,7 @@ module Spree
# Sort shipping methods by distributor name
# ! Code copied from Spree::Admin::ResourceController with two added lines
def collection
return parent.send(controller_name) if parent_data.present?
return parent.public_send(controller_name) if parent_data.present?
collection = if model_class.respond_to?(:accessible_by) &&
!current_ability.has_block?(params[:action], model_class)

View File

@@ -7,10 +7,6 @@ class AngularFormBuilder < ActionView::Helpers::FormBuilder
end
def ng_text_field(method, options = {})
# @object_name --> "enterprise_fee_set"
# @fields_for_record_name --> :collection
# @object.send(@fields_for_record_name).first.class.to_s.underscore --> enterprise_fee
value = "{{ #{angular_model(method)} }}"
options.reverse_merge!({'id' => angular_id(method)})
@@ -46,6 +42,6 @@ class AngularFormBuilder < ActionView::Helpers::FormBuilder
end
def angular_model(method)
"#{@object.send(@fields_for_record_name).first.class.to_s.underscore}.#{method}"
"#{@object.public_send(@fields_for_record_name).first.class.to_s.underscore}.#{method}"
end
end

View File

@@ -11,7 +11,7 @@ module AngularFormHelper
def ng_options_from_collection_for_select(collection, value_method, text_method, angular_field)
options = collection.map do |element|
[element.send(text_method), element.send(value_method)]
[element.public_send(text_method), element.public_send(value_method)]
end
ng_options_for_select(options, angular_field)

View File

@@ -15,7 +15,7 @@ module ApplicationHelper
# spree.foo_path in any view rendered from non-spree-namespaced controllers.
def method_missing(method, *args, &block)
if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && spree.respond_to?(method)
spree.send(method, *args)
spree.public_send(method, *args)
else
super
end

View File

@@ -20,7 +20,7 @@ class ColumnPreference < ActiveRecord::Base
def self.for(user, action_name)
stored_preferences = where(user_id: user.id, action_name: action_name)
default_preferences = send("#{action_name}_columns")
default_preferences = __send__("#{action_name}_columns")
filter(default_preferences, user, action_name)
default_preferences.each_with_object([]) do |(column_name, default_attributes), preferences|
stored_preference = stored_preferences.find_by_column_name(column_name)
@@ -37,7 +37,7 @@ class ColumnPreference < ActiveRecord::Base
private
def self.valid_columns_for(action_name)
send("#{action_name}_columns").keys.map(&:to_s)
__send__("#{action_name}_columns").keys.map(&:to_s)
end
def self.known_actions

View File

@@ -12,7 +12,7 @@ class ModelSet
@collection = attributes[:collection] if attributes[:collection]
attributes.each do |name, value|
send("#{name}=", value)
public_send("#{name}=", value)
end
end

View File

@@ -204,7 +204,7 @@ module ProductImport
when 'overwrite_all'
object.assign_attributes(attribute => setting['value'])
when 'overwrite_empty'
if object.send(attribute).blank? || ((attribute == 'on_hand' || attribute == 'count_on_hand') && entry.on_hand_nil)
if object.public_send(attribute).blank? || ((attribute == 'on_hand' || attribute == 'count_on_hand') && entry.on_hand_nil)
object.assign_attributes(attribute => setting['value'])
end
end

View File

@@ -169,7 +169,7 @@ module ProductImport
return if category.blank?
if index.key? category
entry.send("#{type}_category_id=", index[category])
entry.public_send("#{type}_category_id=", index[category])
else
mark_as_invalid(entry, attribute: "#{type}_category", error: I18n.t('admin.product_import.model.not_found'))
end

View File

@@ -71,7 +71,7 @@ module ProductImport
units.converted_attributes.each do |attr, value|
if respond_to?("#{attr}=")
send("#{attr}=", value) unless non_product_attributes.include?(attr)
public_send("#{attr}=", value) unless non_product_attributes.include?(attr)
end
end
end

View File

@@ -19,7 +19,7 @@ class ProxyOrder < ActiveRecord::Base
def state
# NOTE: the order is important here
%w(canceled paused pending cart).each do |state|
return state if send("#{state}?")
return state if __send__("#{state}?")
end
order.state
end
@@ -32,7 +32,7 @@ class ProxyOrder < ActiveRecord::Base
return false unless order_cycle.orders_close_at.andand > Time.zone.now
transaction do
update_column(:canceled_at, Time.zone.now)
order.send('cancel') if order
order.cancel if order
true
end
end
@@ -41,7 +41,7 @@ class ProxyOrder < ActiveRecord::Base
return false unless order_cycle.orders_close_at.andand > Time.zone.now
transaction do
update_column(:canceled_at, nil)
order.send('resume') if order
order.resume if order
true
end
end

View File

@@ -18,15 +18,15 @@ Spree::Calculator::DefaultTax.class_eval do
# Added this block, finds relevant fees for each line_item, calculates the tax on them, and returns the total tax
per_item_fees_total = order.line_items.sum do |line_item|
calculator.send(:per_item_enterprise_fee_applicators_for, line_item.variant)
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
.select { |applicator| (!applicator.enterprise_fee.inherits_tax_category && applicator.enterprise_fee.tax_category == rate.tax_category) ||
(applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
(applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
}
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
end
# Added this block, finds relevant fees for whole order, calculates the tax on them, and returns the total tax
per_order_fees_total = calculator.send(:per_order_enterprise_fee_applicators_for, order)
per_order_fees_total = calculator.per_order_enterprise_fee_applicators_for(order)
.select { |applicator| applicator.enterprise_fee.tax_category == rate.tax_category }
.sum { |applicator| applicator.enterprise_fee.compute_amount(order) }

View File

@@ -15,7 +15,7 @@ module Spree::Preferences
def get_preference(key)
if !has_preference?(key) && has_attachment?(key)
send key
public_send key
else
super key
end

View File

@@ -51,7 +51,7 @@ class Subscription < ActiveRecord::Base
def state
# NOTE: the order is important here
%w(canceled paused pending ended).each do |state|
return state if send("#{state}?")
return state if __send__("#{state}?")
end
"active"
end

View File

@@ -15,7 +15,7 @@ class Api::Admin::EnterpriseFeeSerializer < ActiveModel::Serializer
result = nil
options[:controller].send(:with_format, :html) do
options[:controller].__send__(:with_format, :html) do
result = options[:controller].render_to_string :partial => 'admin/enterprise_fees/calculator_settings', :locals => {:enterprise_fee => object}
end

View File

@@ -83,7 +83,7 @@ class OrderSyncer
def addresses_match?(order_address, subscription_address)
relevant_address_attrs.all? do |attr|
order_address[attr] == subscription_address.send("#{attr}_was") ||
order_address[attr] == subscription_address.public_send("#{attr}_was") ||
order_address[attr] == subscription_address[attr]
end
end
@@ -101,7 +101,7 @@ class OrderSyncer
# address on the order matches the shop's address
def force_ship_address_required?(order)
return false unless shipping_method.require_ship_address?
distributor_address = order.send(:address_from_distributor)
distributor_address = order.__send__(:address_from_distributor)
relevant_address_attrs.all? do |attr|
order.ship_address[attr] == distributor_address[attr]
end

View File

@@ -42,7 +42,7 @@ module Discourse
if BOOLS.include? k
val = ["true", "false"].include?(val) ? val == "true" : nil
end
sso.send("#{k}=", val)
sso.public_send("#{k}=", val)
end
decoded_hash.each do |k,v|
@@ -87,9 +87,9 @@ module Discourse
def unsigned_payload
payload = {}
ACCESSORS.each do |k|
next if (val = send k) == nil
next if (val = public_send k) == nil
payload[k] = val
payload[k] = val
end
if @custom_fields

View File

@@ -12,7 +12,7 @@ module OpenFoodNetwork
args.each do |arg|
type = types[arg.class]
next unless type
send("#{type}=", arg)
public_send("#{type}=", arg)
end
end
@@ -24,16 +24,6 @@ module OpenFoodNetwork
customer_preferred_ship_address || user_preferred_ship_address || fallback_ship_address
end
private
def types
{
String => "email",
Customer => "customer",
Spree::User => "user"
}
end
def email=(arg)
@email ||= arg
end
@@ -46,6 +36,16 @@ module OpenFoodNetwork
@user ||= arg
end
private
def types
{
String => "email",
Customer => "customer",
Spree::User => "user"
}
end
def customer_preferred_bill_address
customer.andand.bill_address
end

View File

@@ -58,6 +58,41 @@ module OpenFoodNetwork
end
end
def per_item_enterprise_fee_applicators_for(variant)
fees = []
return [] unless @order_cycle && @distributor
@order_cycle.exchanges_carrying(variant, @distributor).each do |exchange|
exchange.enterprise_fees.per_item.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, variant, exchange.role)
end
end
@order_cycle.coordinator_fees.per_item.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, variant, 'coordinator')
end
fees
end
def per_order_enterprise_fee_applicators_for(order)
fees = []
return fees unless @order_cycle && order.distributor
@order_cycle.exchanges_supplying(order).each do |exchange|
exchange.enterprise_fees.per_order.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, nil, exchange.role)
end
end
@order_cycle.coordinator_fees.per_order.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, nil, 'coordinator')
end
fees
end
private
@@ -104,41 +139,5 @@ module OpenFoodNetwork
line_item = OpenStruct.new variant: variant, quantity: 1, price: variant.price, amount: variant.price
enterprise_fee.compute_amount(line_item)
end
def per_item_enterprise_fee_applicators_for(variant)
fees = []
return [] unless @order_cycle && @distributor
@order_cycle.exchanges_carrying(variant, @distributor).each do |exchange|
exchange.enterprise_fees.per_item.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, variant, exchange.role)
end
end
@order_cycle.coordinator_fees.per_item.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, variant, 'coordinator')
end
fees
end
def per_order_enterprise_fee_applicators_for(order)
fees = []
return fees unless @order_cycle && order.distributor
@order_cycle.exchanges_supplying(order).each do |exchange|
exchange.enterprise_fees.per_order.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, nil, exchange.role)
end
end
@order_cycle.coordinator_fees.per_order.each do |enterprise_fee|
fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, nil, 'coordinator')
end
fees
end
end
end

View File

@@ -4,18 +4,18 @@
module OpenFoodNetwork
module Paperclippable
def self.included(base)
base.send :extend, ActiveModel::Naming
base.send :extend, ActiveModel::Callbacks
base.send :include, ActiveModel::Validations
base.send :include, Paperclip::Glue
base.extend(ActiveModel::Naming)
base.extend(ActiveModel::Callbacks)
base.include(ActiveModel::Validations)
base.include(Paperclip::Glue)
# Paperclip required callbacks
base.send :define_model_callbacks, :save, only: [:after]
base.send :define_model_callbacks, :commit, only: [:after]
base.send :define_model_callbacks, :destroy, only: [:before, :after]
base.define_model_callbacks(:save, only: [:after])
base.define_model_callbacks(:commit, only: [:after])
base.define_model_callbacks(:destroy, only: [:before, :after])
# Initialise an ID
base.send :attr_accessor, :id
base.__send__(:attr_accessor, :id)
base.instance_variable_set :@id, 1
end

View File

@@ -8,7 +8,7 @@ module OpenFoodNetwork
end
def scope(product)
product.send :extend, OpenFoodNetwork::ScopeProductToHub::ScopeProductToHub
product.extend(OpenFoodNetwork::ScopeProductToHub::ScopeProductToHub)
product.instance_variable_set :@hub, @hub
product.instance_variable_set :@variant_overrides, @variant_overrides
end

View File

@@ -6,7 +6,7 @@ module OpenFoodNetwork
end
def scope(variant)
variant.send :extend, OpenFoodNetwork::ScopeVariantToHub::ScopeVariantToHub
variant.extend(OpenFoodNetwork::ScopeVariantToHub::ScopeVariantToHub)
variant.instance_variable_set :@hub, @hub
variant.instance_variable_set :@variant_override, @variant_overrides[variant]
end

View File

@@ -24,6 +24,11 @@ module OpenFoodNetwork
end
end
def rules
return @rules unless @rules.nil?
@rules = rule_class.prioritised.for(enterprise)
end
private
def reject?(element)
@@ -38,11 +43,6 @@ module OpenFoodNetwork
false
end
def rules
return @rules unless @rules.nil?
@rules = rule_class.prioritised.for(enterprise)
end
def customer_rules
return @customer_matched_rules unless @customer_matched_rules.nil?
@customer_matched_rules = rules.select{ |rule| customer_tags_match?(rule) }

View File

@@ -20,7 +20,9 @@ module Spree
let!(:current_api_user) do
user = create(:user)
user.spree_roles = []
enterprises.each { |e| user.enterprise_roles.create(enterprise: send(e)) }
enterprises.each do |enterprise|
user.enterprise_roles.create(enterprise: public_send(enterprise))
end
user.save!
user
end

View File

@@ -17,7 +17,7 @@ module Stripe
attrs = source_attrs_from(response)
@payment.source.update_attributes!(attrs)
else
@payment.send(:gateway_error, response.message)
@payment.__send__(:gateway_error, response.message)
end
end

View File

@@ -6,7 +6,7 @@ module Stripe
def handle
return :unknown unless known_event?
send(event_mappings[@event.type])
__send__(event_mappings[@event.type])
end
private