Sha256: 4ebcefead9928d857198a75d5c2cf82c20f53e71e0f9d643d0deb4712ebb0c7b

Contents?: true

Size: 931 Bytes

Versions: 25

Compression:

Stored size: 931 Bytes

Contents

module Spree
  class Calculator < ActiveRecord::Base
    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.all
    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

25 entries across 25 versions & 2 rubygems

Version Path
spree_core-1.3.5 app/models/spree/calculator.rb
spree_core-1.3.4 app/models/spree/calculator.rb
spree_core-1.3.3 app/models/spree/calculator.rb
spree_core-1.2.5 app/models/spree/calculator.rb
spree_core-1.1.6 app/models/spree/calculator.rb
spree_core-1.1.5 app/models/spree/calculator.rb
spree_core-1.2.4 app/models/spree/calculator.rb
spree_core-1.3.2 app/models/spree/calculator.rb
spree_core-1.2.3 app/models/spree/calculator.rb
spree_core-1.3.1 app/models/spree/calculator.rb
spree_core-1.3.0 app/models/spree/calculator.rb
spree_core-1.3.0.rc2 app/models/spree/calculator.rb
dup_spree_core-1.3.0.rc1 app/models/spree/calculator.rb
spree_core-1.3.0.rc1 app/models/spree/calculator.rb
spree_core-1.2.2 app/models/spree/calculator.rb
spree_core-1.1.4 app/models/spree/calculator.rb
spree_core-1.2.0 app/models/spree/calculator.rb
spree_core-1.2.0.rc2 app/models/spree/calculator.rb
spree_core-1.2.0.rc1 app/models/spree/calculator.rb
spree_core-1.1.3 app/models/spree/calculator.rb