mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Inspecting 1513 files
..........................................................................................................................................................................................................................................................................................................................C...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C......................................................................................................................................................................................................................................................................................................................................................................................................................................................................C...........................................................................................................
Offenses:
app/models/spree/calculator.rb:31:48: C: [Corrected] Style/RedundantStringEscape: Redundant escape of / inside string literal.
self.class.name.titleize.gsub("Calculator\/", "")
^^
spec/controllers/spree/admin/shipping_methods_controller_spec.rb:40:78: C: [Corrected] Style/RedundantStringEscape: Redundant escape of ' inside string literal.
params[:shipping_method][:calculator_attributes][shipping_amount] = "\'20.0'"
^^
spec/system/admin/enterprise_fees_spec.rb:82:78: C: [Corrected] Style/RedundantStringEscape: Redundant escape of ' inside string literal.
fill_in("#{prefix}_calculator_attributes_preferred_flat_percent", with: "\'20.0'")
^^
spec/system/admin/enterprise_fees_spec.rb:140:42: C: [Corrected] Style/RedundantStringEscape: Redundant escape of ' inside string literal.
'preferred_flat_percent', with: "\'20.0'"
^^
1513 files inspected, 4 offenses detected, 4 offenses corrected
59 lines
1.4 KiB
Ruby
59 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class Calculator < ApplicationRecord
|
|
self.belongs_to_required_by_default = false
|
|
|
|
belongs_to :calculable, polymorphic: true
|
|
|
|
# This method must be overriden in concrete calculator.
|
|
#
|
|
# It should return amount computed based on #calculable and/or optional parameter
|
|
def compute(_something = nil)
|
|
raise NotImplementedError, 'please use concrete calculator'
|
|
end
|
|
|
|
# overwrite to provide description for your calculators
|
|
def self.description
|
|
'Base Calculator'
|
|
end
|
|
|
|
###################################################################
|
|
|
|
def self.register(*klasses); end
|
|
|
|
# Returns all calculators applicable for kind of work
|
|
def self.calculators
|
|
Rails.application.config.spree.calculators
|
|
end
|
|
|
|
def to_s
|
|
self.class.name.titleize.gsub("Calculator/", "")
|
|
end
|
|
|
|
def description
|
|
self.class.description
|
|
end
|
|
|
|
def available?(_object)
|
|
true
|
|
end
|
|
|
|
private
|
|
|
|
# Given an object which might be an Order or a LineItem (amongst
|
|
# others), return a collection of line items.
|
|
def line_items_for(object)
|
|
if object.is_a?(Spree::LineItem)
|
|
[object]
|
|
elsif object.respond_to? :line_items
|
|
object.line_items
|
|
elsif object.respond_to?(:order) && object.order.present?
|
|
object.order.line_items
|
|
else
|
|
[object]
|
|
end
|
|
end
|
|
end
|
|
end
|