Module: ActsAsSubscribable::SubscribableMethods
- Defined in:
- lib/acts_as_subscribable/subscribable_methods.rb,
lib/acts_as_subscribable/subscribable_methods/instance_methods.rb
Defined Under Namespace
Modules: InstanceMethods
Instance Method Summary collapse
Instance Method Details
#acts_as_subscribable(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/acts_as_subscribable/subscribable_methods.rb', line 5 def acts_as_subscribable( = {}) .reverse_merge! :subscriber => "User", :subscription => "Subscription", :subscriber_id => :subscriber_id, :subscribed_id => :subscribed_id [:subscription] = [:subscription].to_s [:subscriber] = [:subscriber].to_s subscriber_const = [:subscriber].constantize subscriber_table = [:subscriber].tableize subscription_const = [:subscription].constantize has_many :subscriptions, :class_name => [:subscription], :dependent => :destroy has_many subscriber_table, :class_name => [:subscriber], :through => :subscriptions, :foreign_key => [:subscriber_id] subscriber_const.has_many :subscriptions, :class_name => [:subscription], :dependent => :destroy # subscriber_const.has_many self.name.tableize.to_sym, :class_name => self.name, :through => :subscriptions, :foreign_key => options[:subscribed_id] subscription_const.belongs_to [:subscriber].downcase.to_sym subscription_const.belongs_to self.name.downcase.to_sym send(:include, ActsAsSubscribable::SubscribableMethods::InstanceMethods) class_eval "def acts_as_subscribable_options; { :subscriber => '#{[:subscriber]}', :subscription => '#{[:subscription]}' }; end" end |