Class: Webhookdb::Replicator
- Inherits:
-
Object
- Object
- Webhookdb::Replicator
show all
- Extended by:
- MethodUtilities
- Includes:
- Appydays::Configurable
- Defined in:
- lib/webhookdb/replicator.rb
Defined Under Namespace
Modules: ConvertkitV1Mixin, FrontV1Mixin, GithubRepoV1Mixin, IncreaseV1Mixin, IntercomV1Mixin, OAuthRefreshAccessTokenMixin, ShopifyV1Mixin, SponsyV1Mixin, StripeV1Mixin, TransistorV1Mixin
Classes: AtomSingleFeedV1, AwsPricingV1, Base, Column, ConvertkitBroadcastV1, ConvertkitSubscriberV1, ConvertkitTagV1, CredentialsMissing, Descriptor, Docgen, EmailOctopusCampaignV1, EmailOctopusContactV1, EmailOctopusEventV1, EmailOctopusListV1, Fake, FakeBackfillOnly, FakeBackfillWithCriteria, FakeDependent, FakeDependentDependent, FakeEnqueueBackfillOnCreate, FakeExhaustiveConverter, FakeWebhooksOnly, FakeWithEnrichments, FrontConversationV1, FrontMarketplaceRootV1, FrontMessageV1, FrontSignalwireMessageChannelAppV1, GithubIssueCommentV1, GithubIssueV1, GithubPullV1, GithubReleaseV1, GithubRepositoryEventV1, IcalendarCalendarV1, IcalendarEventV1, IncreaseACHTransferV1, IncreaseAccountNumberV1, IncreaseAccountTransferV1, IncreaseAccountV1, IncreaseAppV1, IncreaseCheckTransferV1, IncreaseEventV1, IncreaseLimitV1, IncreaseTransactionV1, IncreaseWireTransferV1, IndexSpec, IntercomContactV1, IntercomConversationV1, IntercomMarketplaceRootV1, Invalid, PlivoSmsInboundV1, PostmarkInboundMessageV1, PostmarkOutboundMessageEventV1, SchemaModification, ShopifyCustomerV1, ShopifyOrderV1, SignalwireMessageV1, SponsyCustomerV1, SponsyPlacementV1, SponsyPublicationV1, SponsySlotV1, SponsyStatusV1, StateMachineStep, StripeChargeV1, StripeCouponV1, StripeCustomerV1, StripeDisputeV1, StripeInvoiceItemV1, StripeInvoiceV1, StripePayoutV1, StripePriceV1, StripeProductV1, StripeRefundV1, StripeSubscriptionItemV1, StripeSubscriptionV1, TransistorEpisodeStatsV1, TransistorEpisodeV1, TransistorShowV1, TwilioSmsV1, UrlRecorderV1, WebhookRequest, WebhookdbCustomerV1
Constant Summary
collapse
- PLUGIN_DIRNAME =
"replicator_ext"
- PLUGIN_DIR =
Pathname(__FILE__).dirname + PLUGIN_DIRNAME
Class Method Summary
collapse
attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader
Class Method Details
._require_files(dir) ⇒ Object
199
200
201
202
203
204
205
|
# File 'lib/webhookdb/replicator.rb', line 199
def _require_files(dir)
splitter = "webhookdb/" + dir.to_s.rpartition("/").last
dir.glob("*.rb").each do |path|
base = path.basename.to_s[..-4]
require("#{splitter}/#{base}")
end
end
|
Return a new replicator for the given integration.
164
165
166
167
168
|
# File 'lib/webhookdb/replicator.rb', line 164
def create(service_integration)
name = service_integration.service_name
descr = self.registered!(name)
return descr.ctor.call(service_integration)
end
|
222
223
224
225
226
227
|
# File 'lib/webhookdb/replicator.rb', line 222
def find_at_root!(sint, service_name:)
root = self.find_root(sint)
bad_auth = root&.service_name != service_name
raise self::CredentialsMissing, "Could not find root integration for #{sint.inspect}" if bad_auth
return root
end
|
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/webhookdb/replicator.rb', line 209
def find_root(sint)
max_depth = 15
parent = sint.depends_on
return sint if parent.nil?
max_depth.times do
return parent if parent.depends_on.nil?
parent = parent.depends_on
end
return nil
end
|
.load_replicators ⇒ Object
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/webhookdb/replicator.rb', line 185
def load_replicators
existing_descendants = Webhookdb::Replicator::Base.descendants
["replicator", PLUGIN_DIRNAME].each do |d|
Gem.find_files(File.join("webhookdb/#{d}/*.rb")).each do |path|
next if path.include?("/spec/")
require path
end
end
new_descendants = Webhookdb::Replicator::Base.descendants
newly_registered = new_descendants - existing_descendants
newly_registered.each { |cls| self.register(cls) }
return newly_registered
end
|
.register(cls) ⇒ Object
154
155
156
157
158
|
# File 'lib/webhookdb/replicator.rb', line 154
def register(cls)
desc = cls.descriptor
raise TypeError, "descriptor must be a Descriptor, got #{desc.class.name}" unless desc.is_a?(Descriptor)
self.registry[desc.name] = desc
end
|
Returns the service with the given name, or nil
if none is registered.
172
173
174
|
# File 'lib/webhookdb/replicator.rb', line 172
def registered(name)
return @registry[name]
end
|
178
179
180
181
182
183
|
# File 'lib/webhookdb/replicator.rb', line 178
def registered!(name)
raise ArgumentError, "name cannot be blank" if name.blank?
r = self.registered(name)
return r if r
raise Invalid, name
end
|
150
151
152
|
# File 'lib/webhookdb/replicator.rb', line 150
def registry
return @registry ||= {}
end
|