app/models/piggybak/payment_method.rb in piggybak-0.2.0 vs app/models/piggybak/payment_method.rb in piggybak-0.2.1

- old
+ new

@@ -1,31 +1,28 @@ module Piggybak class PaymentMethod < ActiveRecord::Base - - # klass_enum requires the ShippingCalculator subclasses to be loaded - shipping_calcs_path = File.expand_path("../payment_calculator", __FILE__) - Dir.glob(shipping_calcs_path + "**/*.rb").each do |subclass| - ActiveSupport::Dependencies.require_or_load subclass - end - has_many :payment_method_values, :dependent => :destroy alias :metadata :payment_method_values accepts_nested_attributes_for :payment_method_values, :allow_destroy => true validates_presence_of :klass validates_presence_of :description def klass_enum - Piggybak::PaymentCalculator.subclasses + Piggybak.config.payment_calculators end validates_each :payment_method_values do |record, attr, value| if record.klass payment_method = record.klass.constantize metadata_keys = value.collect { |v| v.key }.sort if payment_method::KEYS.sort != metadata_keys - record.errors.add attr, "You must define key values for #{payment_method::KEYS.join(', ')} for this payment method." + if payment_method::KEYS.empty? + record.errors.add attr, "You don't need any metadata for this method." + else + record.errors.add attr, "You must define key values for #{payment_method::KEYS.join(', ')} for this payment method." + end end end end validates_each :active do |record, attr, value| if value && PaymentMethod.find_all_by_active(true).select { |p| p != record }.size > 0