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, install_url: nil, documentable: nil) ⇒ Descriptor

Returns a new instance of Descriptor.

Raises:

  • (ArgumentError)


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
117
118
119
120
121
122
123
124
# File 'lib/webhookdb/replicator.rb', line 90

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,
  install_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:,
    install_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.



83
84
85
# File 'lib/webhookdb/replicator.rb', line 83

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.



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

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?



86
87
88
# File 'lib/webhookdb/replicator.rb', line 86

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

#install_urlObject (readonly)

If this integration uses /v1/install to set up, or some other link like a marketplace URL, provide it here. Note that you can add a redirect to Webhookdb::Apps::REDIRECTS to provide a pretty, arbitrary URL.



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

def install_url
  @install_url
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



130
131
132
133
134
# File 'lib/webhookdb/replicator.rb', line 130

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)


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

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

#documentable?Boolean

Returns:

  • (Boolean)


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

def documentable? = @documentable

#inspectObject



126
127
128
# File 'lib/webhookdb/replicator.rb', line 126

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

#supports_webhooks_and_backfill?Boolean

Returns:

  • (Boolean)


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

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

#webhooks_only?Boolean

Returns:

  • (Boolean)


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

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