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
101 102 103 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 101 def __promiscuous_fetch_new(id) new.tap { |m| m.__send__("#{subscribe_foreign_key}=", id) } end |
#__promiscuous_missing_record_exception ⇒ Object
97 98 99 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 97 def __promiscuous_missing_record_exception None end |
#inherited(subclass) ⇒ Object
90 91 92 93 94 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 90 def inherited(subclass) super subclass.subscribed_attrs = self.subscribed_attrs.dup subclass.register_klass end |
#register_klass(options = {}) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 82 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/promiscuous/subscriber/model/base.rb', line 63 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 |