Class: Webhookdb::Replicator

Inherits:
Object
  • Object
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, IncreaseCheckTransferV1, 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, WebhookRequest, WebhookdbCustomerV1

Constant Summary collapse

PLUGIN_DIRNAME =
"replicator_ext"
PLUGIN_DIR =
Pathname(__FILE__).dirname + PLUGIN_DIRNAME

Class Method Summary collapse

Methods included from MethodUtilities

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



191
192
193
194
195
196
197
# File 'lib/webhookdb/replicator.rb', line 191

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

.create(service_integration) ⇒ Webhookdb::Replicator::Base

Return a new replicator for the given integration.

Parameters:

Returns:



156
157
158
159
160
# File 'lib/webhookdb/replicator.rb', line 156

def create(service_integration)
  name = service_integration.service_name
  descr = self.registered!(name)
  return descr.ctor.call(service_integration)
end

.find_at_root!(sint, service_name:) ⇒ Webhookdb::ServiceIntegration

Parameters:

Returns:

Raises:

  • (self::CredentialsMissing)


214
215
216
217
218
219
# File 'lib/webhookdb/replicator.rb', line 214

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

.find_root(sint) ⇒ Webhookdb::ServiceIntegration?



201
202
203
204
205
206
207
208
209
210
# File 'lib/webhookdb/replicator.rb', line 201

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_replicatorsObject



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/webhookdb/replicator.rb', line 177

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

Raises:

  • (TypeError)


146
147
148
149
150
# File 'lib/webhookdb/replicator.rb', line 146

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

.registered(name) ⇒ Webhookdb::Replicator::Descriptor

Returns the service with the given name, or nil if none is registered.



164
165
166
# File 'lib/webhookdb/replicator.rb', line 164

def registered(name)
  return @registry[name]
end

.registered!(name) ⇒ Webhookdb::Replicator::Descriptor

Returns:

Raises:



170
171
172
173
174
175
# File 'lib/webhookdb/replicator.rb', line 170

def registered!(name)
  raise ArgumentError, "name cannot be blank" if name.blank?
  r = self.registered(name)
  return r if r
  raise Invalid, name
end

.registryHash{String => Webhookdb::Replicator::Descriptor}

Returns:



142
143
144
# File 'lib/webhookdb/replicator.rb', line 142

def registry
  return @registry ||= {}
end