Sha256: 1631bdd4ea9142b67d28656c4af2ed2aa9c01fc5c8a8b72832358f00e6b821ff
Contents?: true
Size: 1.28 KB
Versions: 14
Compression:
Stored size: 1.28 KB
Contents
module Spree class Calculator < ActiveRecord::Base belongs_to :calculable, polymorphic: true # This method calls a compute_<computable> method. must be overriden in concrete calculator. # # It should return amount computed based on #calculable and the computable parameter def compute(computable) # Spree::LineItem -> :compute_line_item computable_name = computable.class.name.demodulize.underscore method = "compute_#{computable_name}".to_sym calculator_class = self.class if respond_to?(method) self.send(method, computable) else raise NotImplementedError, "Please implement '#{method}(#{computable_name})' in your calculator: #{calculator_class.name}" end 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 end end
Version data entries
14 entries across 14 versions & 1 rubygems