Module: Promiscuous::Subscriber::Model::Base::ClassMethods
- Defined in:
- lib/promiscuous/subscriber/model/base.rb
Defined Under Namespace
Classes: None
Instance Method Summary collapse
- #__promiscuous_fetch_new(id) ⇒ Object
- #__promiscuous_missing_record_exception ⇒ Object
- #inherited(subclass) ⇒ Object
- #register_klass(options = {}) ⇒ Object
- #subscribe(*args) ⇒ Object
Instance Method Details
#__promiscuous_fetch_new(id) ⇒ Object
100 101 102 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 100 def __promiscuous_fetch_new(id) new.tap { |m| m.__send__("#{subscribe_foreign_key}=", id) } end |
#__promiscuous_missing_record_exception ⇒ Object
96 97 98 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 96 def __promiscuous_missing_record_exception None end |
#inherited(subclass) ⇒ Object
89 90 91 92 93 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 89 def inherited(subclass) super subclass.subscribed_attrs = self.subscribed_attrs.dup subclass.register_klass end |
#register_klass(options = {}) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 81 def register_klass(={}) subscribe_as = [:as].try(:to_s) || self.name return unless subscribe_as Promiscuous::Subscriber::Model.mapping[self.subscribe_from] ||= {} Promiscuous::Subscriber::Model.mapping[self.subscribe_from][subscribe_as] = self end |
#subscribe(*args) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 62 def subscribe(*args) = args. attributes = args # TODO reject invalid options self.subscribe_foreign_key = [:foreign_key] if [:foreign_key] ([self] + descendants).each { |klass| klass.subscribed_attrs |= attributes } if self.subscribe_from && [:from] && self.subscribe_from != [:from] raise 'Subscribing from different publishers is not supported yet' end self.subscribe_from ||= [:from].try(:to_s) || "*" self.register_klass() end |