Skip to content

Commit

Permalink
Fix current violations of Style/Send cop
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Aug 31, 2018
1 parent 1de13a5 commit c8b0d0f
Show file tree
Hide file tree
Showing 34 changed files with 74 additions and 77 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/contents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def edit
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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/inventory_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InventoryItemsController < ResourceController
# 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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/product_import_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def process_data(method)
@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
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ def new_object_url(options = {})

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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/shop_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def changeable_orders_alert
private

def filtered_json(products_json)
if applicator.send(:rules).any?
if applicator.rules.any?
filter(products_json)
else
products_json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def edit
@preferences_general << :bugherd_api_key
end
end
GeneralSettingsController.send(:prepend, GeneralSettingsEditPreferences)
GeneralSettingsController.prepend(GeneralSettingsEditPreferences)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Admin
# 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.controller_name if parent_data.present?
collection = if model_class.respond_to?(:accessible_by) &&
!current_ability.has_block?(params[:action], model_class)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def fire

# 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def load_resource
end
end

Spree::Admin::ResourceController.send(:prepend, AuthorizeOnLoadResource)
Spree::Admin::ResourceController.prepend(AuthorizeOnLoadResource)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Admin
# 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.controller_name if parent_data.present?

collection = if model_class.respond_to?(:accessible_by) &&
!current_ability.has_block?(params[:action], model_class)
Expand Down
6 changes: 1 addition & 5 deletions app/helpers/angular_form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ def ng_fields_for(record_name, *args, &block)
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)})

Expand Down Expand Up @@ -46,6 +42,6 @@ def angular_id(method)
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
2 changes: 1 addition & 1 deletion app/helpers/angular_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def ng_options_for_select(container, angular_field=nil)

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)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def ng_form_for(name, *args, &block)
# 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
Expand Down
4 changes: 2 additions & 2 deletions app/models/column_preference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,7 +37,7 @@ def self.for(user, action_name)
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/model_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(klass, collection, attributes={}, reject_if=nil, delete_if=nil)
@collection = attributes[:collection] if attributes[:collection]

attributes.each do |name, value|
send("#{name}=", value)
public_send("#{name}=", value)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/product_import/entry_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def assign_defaults(object, entry)
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/product_import/entry_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def tax_and_shipping_validation(entry, type, category, index)
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/product_import/spreadsheet_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def assign_units(attrs)

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
Expand Down
6 changes: 3 additions & 3 deletions app/models/proxy_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +32,7 @@ def cancel
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
Expand All @@ -41,7 +41,7 @@ def resume
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
Expand Down
6 changes: 3 additions & 3 deletions app/models/spree/calculator/default_tax_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def compute_order(order)

# 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) }

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/preferences/file_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.preference(name, type, *args)

def get_preference(key)
if !has_preference?(key) && has_attachment?(key)
send key
public_send key
else
super key
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def paused?
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
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/api/admin/enterprise_fee_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def calculator_settings

result = nil

options[:controller].send(:with_format, :html) do
options[:controller].public_send(:with_format, :html) do
result = options[:controller].render_to_string :partial => 'admin/enterprise_fees/calculator_settings', :locals => {:enterprise_fee => object}
end

Expand Down
4 changes: 2 additions & 2 deletions app/services/order_syncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def relevant_address_attrs

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
Expand All @@ -101,7 +101,7 @@ def ship_address_updatable?(order)
# 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
Expand Down
6 changes: 3 additions & 3 deletions lib/discourse/single_sign_on.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.parse(payload, sso_secret = nil)
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|
Expand Down Expand Up @@ -87,9 +87,9 @@ def payload
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
Expand Down
2 changes: 1 addition & 1 deletion lib/open_food_network/address_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(*args)
args.each do |arg|
type = types[arg.class]
next unless type
send("#{type}=", arg)
public_send("#{type}=", arg)
end
end

Expand Down
35 changes: 17 additions & 18 deletions lib/open_food_network/enterprise_fee_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ def create_order_adjustments_for(order)
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

private

Expand Down Expand Up @@ -105,24 +122,6 @@ def calculate_fee_for(variant, enterprise_fee)
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 = []

Expand Down
16 changes: 8 additions & 8 deletions lib/open_food_network/paperclippable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/open_food_network/scope_product_to_hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(hub)
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
Expand Down
Loading

0 comments on commit c8b0d0f

Please sign in to comment.