Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- require_relative "order_item"
- require_relative "customer"
- class PaymentType
- include DataMapper::Resource
- has n, :orders
- # NOTE: COD (cash on delivery), "dobirka" in Czech
- property :id, Serial
- property :name, String
- property :shortcut, String, default: lambda { |instance, property| instance.name.downcase }
- def initialize(*args)
- super(*args)
- self.include_payment_mixin
- end
- def metaclass
- class << self
- self
- end
- end
- def include_payment_mixin
- const_name = self.shortcut.camel_case.to_sym
- relative_path = "models/payment_types/#{self.shortcut}.rb"
- if File.exist?(File.join(Project.root, relative_path))
- Project.import(relative_path)
- Project.logger.info("Including module #{const_name} for #{self.inspect}")
- self.metaclass.send(:include, PaymentTypes.const_get(const_name))
- end
- end
- end
Add Comment
Please, Sign In to add comment