Class: Webhookdb::Replicator::Descriptor

Inherits:
TypedStruct show all
Defined in:
lib/webhookdb/replicator.rb

Overview

Statically describe a replicator.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TypedStruct

#[], #_apply, #_defaults, #as_json, #change

Constructor Details

#initialize(name:, ctor:, resource_name_singular:, feature_roles:, supports_webhooks: false, supports_backfill: false, resource_name_plural: nil, dependency_descriptor: nil, api_docs_url: "", description: nil, enterprise: false, documentation_url: nil, documentable: nil) ⇒ Descriptor

Returns a new instance of Descriptor.

Raises:

  • (ArgumentError)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/webhookdb/replicator.rb', line 84

def initialize(
  name:,
  ctor:,
  resource_name_singular:,
  feature_roles:,
  supports_webhooks: false,
  supports_backfill: false,
  resource_name_plural: nil,
  dependency_descriptor: nil,
  api_docs_url: "",
  description: nil,
  enterprise: false,
  documentation_url: nil,
  documentable: nil
)
  raise ArgumentError, "must support one or both of webhooks and backfill" unless
    supports_webhooks || supports_backfill
  super(
    name:,
    resource_name_singular:,
    feature_roles:,
    supports_webhooks:,
    supports_backfill:,
    dependency_descriptor:,
    documentation_url:,
    api_docs_url:,
    enterprise:
  )
  @ctor = ctor.is_a?(Class) ? ctor.method(:new) : ctor
  @resource_name_plural = resource_name_plural || "#{self.resource_name_singular}s"
  @description = description || "Replicate #{self.resource_name_plural} into your database."
  @documentable = documentable.nil? ? !self.name.start_with?("webhookdb_", "fake_", "theranest_") : documentable
end

Instance Attribute Details

#api_docs_urlObject (readonly)

URL pointing to the provider (not-WebhookDB) docs for this integration.



77
78
79
# File 'lib/webhookdb/replicator.rb', line 77

def api_docs_url
  @api_docs_url
end

#ctorObject

Method invoked with the Webhookdb::ServiceIntegration, and should return a new instance of the integration. Can also be an object that responds to ‘new`.

@return [Proc]


36
37
38
# File 'lib/webhookdb/replicator.rb', line 36

def ctor
  @ctor
end

#dependency_descriptorObject

The descriptor for the service this one depends on (the parent).

@return [Webhookdb::Replicator::Descriptor]


60
61
62
# File 'lib/webhookdb/replicator.rb', line 60

def dependency_descriptor
  @dependency_descriptor
end

#descriptionObject (readonly)

Markdown description of this replicator.



74
75
76
# File 'lib/webhookdb/replicator.rb', line 74

def description
  @description
end

#documentation_urlObject (readonly)

If this integration has specific documentation, link its url here. It is used to build custom error messages, for example in case ‘backfill’ is called but not supported.



71
72
73
# File 'lib/webhookdb/replicator.rb', line 71

def documentation_url
  @documentation_url
end

#enterpriseObject (readonly) Also known as: enterprise?

Is this an enterprise-only replicator?



80
81
82
# File 'lib/webhookdb/replicator.rb', line 80

def enterprise
  @enterprise
end

#feature_rolesObject

Used for feature flagging functionality. Usually will be [], but other possible values are: -‘internal’ e.g. our fake integration -‘unreleased’ for works in progress -‘beta’ if we don’t want most people to have access

@return [Array<String>]


45
46
47
# File 'lib/webhookdb/replicator.rb', line 45

def feature_roles
  @feature_roles
end

#nameObject

Name of the replicator, like ‘stripe_charge_v1’. Appears externally in many places, so must be meaningful.

@return [String]


30
31
32
# File 'lib/webhookdb/replicator.rb', line 30

def name
  @name
end

#resource_name_pluralObject

Defaults to resource_name_singular+s.

@return [String]


55
56
57
# File 'lib/webhookdb/replicator.rb', line 55

def resource_name_plural
  @resource_name_plural
end

#resource_name_singularObject

Name of the resource, like “Acme Sprocket”

@return [String]


50
51
52
# File 'lib/webhookdb/replicator.rb', line 50

def resource_name_singular
  @resource_name_singular
end

#supports_backfillObject (readonly) Also known as: supports_backfill?

True if this integration supports user-driven backfilling, usually by paginating all resources.



66
67
68
# File 'lib/webhookdb/replicator.rb', line 66

def supports_backfill
  @supports_backfill
end

#supports_webhooksObject (readonly) Also known as: supports_webhooks?

True if this integration supports webhooks (real-time or user-built webhook payloads).



63
64
65
# File 'lib/webhookdb/replicator.rb', line 63

def supports_webhooks
  @supports_webhooks
end

Instance Method Details

#==(other) ⇒ Object



122
123
124
125
126
# File 'lib/webhookdb/replicator.rb', line 122

def ==(other)
  return self.class == other.class &&
      self.name == other.name &&
      self.resource_name_singular == other.resource_name_singular
end

#backfill_only?Boolean

Returns:

  • (Boolean)


132
# File 'lib/webhookdb/replicator.rb', line 132

def backfill_only? = !self.supports_webhooks? && self.supports_backfill?

#documentable?Boolean

Returns:

  • (Boolean)


82
# File 'lib/webhookdb/replicator.rb', line 82

def documentable? = @documentable

#inspectObject



118
119
120
# File 'lib/webhookdb/replicator.rb', line 118

def inspect
  return "#{self.class.name}(name: #{self.name})"
end

#supports_webhooks_and_backfill?Boolean

Returns:

  • (Boolean)


133
# File 'lib/webhookdb/replicator.rb', line 133

def supports_webhooks_and_backfill? = self.supports_webhooks? && self.supports_backfill?

#webhooks_only?Boolean

Returns:

  • (Boolean)


131
# File 'lib/webhookdb/replicator.rb', line 131

def webhooks_only? = self.supports_webhooks? && !self.supports_backfill?