app/models/piggybak/shipping_method.rb in piggybak-0.1.1 vs app/models/piggybak/shipping_method.rb in piggybak-0.2.0

- old
+ new

@@ -1,7 +1,14 @@ module Piggybak class ShippingMethod < ActiveRecord::Base + + # klass_enum requires the ShippingCalculator subclasses to be loaded + shipping_calcs_path = File.expand_path("../shipping_calculator", __FILE__) + Dir.glob(shipping_calcs_path + "**/*.rb").each do |subclass| + ActiveSupport::Dependencies.require_or_load subclass + end + has_many :shipping_method_values, :dependent => :destroy alias :metadata :shipping_method_values validates_presence_of :description validates_presence_of :klass @@ -16,15 +23,12 @@ record.errors.add attr, "You must define key values for #{calculator::KEYS.join(', ')} for this shipping method." end end end - def klass_enum - #TODO: Troubleshoot use of subclasses here instead - [Piggybak::ShippingCalculator::FlatRate, - Piggybak::ShippingCalculator::Range, - Piggybak::ShippingCalculator::Pickup] + def klass_enum + Piggybak::ShippingCalculator.subclasses end def self.available_methods(cart) active_methods = ShippingMethod.find_all_by_active(true) @@ -34,13 +38,11 @@ def self.lookup_methods(cart) active_methods = ShippingMethod.find_all_by_active(true) active_methods.inject([]) do |arr, method| klass = method.klass.constantize -logger.warn "steph: inside here!! #{method.inspect}" if klass.available?(method, cart) rate = klass.rate(method, cart) -logger.warn "steph rate is #{rate.inspect}" arr << { :label => "#{method.description} $#{"%.2f" % rate}", :id => method.id, :rate => rate } end