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, PartitionableMixin, ShopifyV1Mixin, SponsyV1Mixin, StripeV1Mixin, TransistorV1Mixin
Classes: AtomSingleFeedV1, AwsPricingV1, Base, BaseStaleRowDeleter, BrokenSpecification, Column, ConvertkitBroadcastV1, ConvertkitSubscriberV1, ConvertkitTagV1, CredentialsMissing, Descriptor, Docgen, EmailOctopusCampaignV1, EmailOctopusContactV1, EmailOctopusEventV1, EmailOctopusListV1, Fake, FakeBackfillOnly, FakeBackfillWithCriteria, FakeDependent, FakeDependentDependent, FakeEnqueueBackfillOnCreate, FakeExhaustiveConverter, FakeHashPartition, FakeRangePartition, FakeStaleRow, FakeStaleRowPartitioned, FakeWebhooksOnly, FakeWithEnrichments, FakeWithWatchChannel, FrontConversationV1, FrontMarketplaceRootV1, FrontMessageV1, FrontSignalwireMessageChannelAppV1, GithubIssueCommentV1, GithubIssueV1, GithubPullV1, GithubReleaseV1, GithubRepositoryEventV1, IcalendarCalendarV1, IcalendarEventV1, IcalendarEventV1Partitioned, 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
202
203
204
205
206
207
208
|
# File 'lib/webhookdb/replicator.rb', line 202
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.
167
168
169
170
171
|
# File 'lib/webhookdb/replicator.rb', line 167
def create(service_integration)
name = service_integration.service_name
descr = self.registered!(name)
return descr.ctor.call(service_integration)
end
|
225
226
227
228
229
230
|
# File 'lib/webhookdb/replicator.rb', line 225
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
|
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/webhookdb/replicator.rb', line 212
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
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/webhookdb/replicator.rb', line 188
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
157
158
159
160
161
|
# File 'lib/webhookdb/replicator.rb', line 157
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.
175
176
177
|
# File 'lib/webhookdb/replicator.rb', line 175
def registered(name)
return @registry[name]
end
|
181
182
183
184
185
186
|
# File 'lib/webhookdb/replicator.rb', line 181
def registered!(name)
raise ArgumentError, "name cannot be blank" if name.blank?
r = self.registered(name)
return r if r
raise Invalid, name
end
|
153
154
155
|
# File 'lib/webhookdb/replicator.rb', line 153
def registry
return @registry ||= {}
end
|