Sha256: f08996c0f6693b36eb33d3b02b34c0847cf52185bbc182e446ada1ec21869853
Contents?: true
Size: 941 Bytes
Versions: 5
Compression:
Stored size: 941 Bytes
Contents
# -*- coding: utf-8 -*- require "active_record" module GetsTrollied def self.included(base) base.extend(ClassMethods) end module ClassMethods def set_up_to_get_trollied(*args) options = args.last.is_a?(Hash) ? args.pop : Hash.new # don't allow multiple calls return if self.included_modules.include?(GetsTrollied::InstanceMethods) send :include, GetsTrollied::InstanceMethods send :has_many, :line_items, :as => :purchasable_item, :dependent => :destroy cattr_accessor :described_as_when_purchasing self.described_as_when_purchasing = options[:described_as] || :name cattr_accessor :as_foreign_key_sym self.as_foreign_key_sym = self.name.foreign_key.to_sym end end module InstanceMethods def place_in(trolley) trolley.add(self) end def description_for_purchasing send(self.class.described_as_when_purchasing) end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
trollied-0.1.4 | lib/gets_trollied.rb |
trollied-0.1.3 | lib/gets_trollied.rb |
trollied-0.1.2 | lib/gets_trollied.rb |
trollied-0.1.1 | lib/gets_trollied.rb |
trollied-0.1.0 | lib/gets_trollied.rb |