Class: WebhookSystem::Subscription
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WebhookSystem::Subscription
- Defined in:
- lib/webhook_system/subscription.rb
Overview
This is the model encompassing the actual record of a webhook subscription
Instance Method Summary collapse
-
#topic_names ⇒ Object
Abstraction around the topics relation, returns an array of the subscribed topic names.
-
#topic_names=(new_topics) ⇒ Object
Abstraction around the topics relation, sets the topic names, requires save to take effect.
-
#url_domain ⇒ Object
Just a helper to get a nice representation of the subscription.
Instance Method Details
#topic_names ⇒ Object
Abstraction around the topics relation, returns an array of the subscribed topic names
26 27 28 |
# File 'lib/webhook_system/subscription.rb', line 26 def topic_names topics.map(&:name) end |
#topic_names=(new_topics) ⇒ Object
Abstraction around the topics relation, sets the topic names, requires save to take effect
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/webhook_system/subscription.rb', line 31 def topic_names=(new_topics) new_topics.reject!(&:blank?) add_topics = new_topics - topic_names new_topics_attributes = [] topics.each do |topic| new_topics_attributes << { id: topic.id, name: topic.name, _destroy: !new_topics.include?(topic.name), } end new_topics_attributes += add_topics.map { |topic| { name: topic } } self.topics_attributes = new_topics_attributes end |
#url_domain ⇒ Object
Just a helper to get a nice representation of the subscription
21 22 23 |
# File 'lib/webhook_system/subscription.rb', line 21 def url_domain URI.parse(url).host end |