Class: TalkToYourApp::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/talk_to_your_app/plugin.rb

Overview

Base class for plugins. A plugin bundles a set of tools and declares the connections and soft-dependency gems it needs. Subclasses use the class-level DSL; instances are not created — everything is declarative metadata read at boot and registration time.

class TalkToYourApp::Plugins::Db < TalkToYourApp::Plugin
  requires_connection :replica_readonly
  tools DbQueryTool
end

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.plugin_nameObject

The registry name this plugin was registered under. Set by the registry.



50
51
52
# File 'lib/talk_to_your_app/plugin.rb', line 50

def plugin_name
  @plugin_name
end

Class Method Details

.log_level(level = NOT_SET) ⇒ Object

Per-plugin audit log level override (defaults to the global level).



45
46
47
# File 'lib/talk_to_your_app/plugin.rb', line 45

def log_level(level = NOT_SET)
  level == NOT_SET ? @log_level : (@log_level = level)
end

.requires_connection(*names) ⇒ Object Also known as: required_connections

One or more connection names this plugin needs declared in the registry.



19
20
21
22
23
# File 'lib/talk_to_your_app/plugin.rb', line 19

def requires_connection(*names)
  @required_connections ||= []
  @required_connections.concat(names.map(&:to_sym)) unless names.empty?
  @required_connections
end

.requires_gem(const = NOT_SET, gem_name: nil) ⇒ Object Also known as: required_gem

Declares a soft-dependency gem. ‘const` is the constant the gem defines (checked at boot); `gem_name` is the human gem name for the error message.



28
29
30
31
32
33
34
# File 'lib/talk_to_your_app/plugin.rb', line 28

def requires_gem(const = NOT_SET, gem_name: nil)
  if const == NOT_SET
    @required_gem
  else
    @required_gem = { const: const.to_s, gem_name: gem_name || const.to_s.downcase }
  end
end

.tools(*tool_classes) ⇒ Object

Tool classes this plugin exposes.



38
39
40
41
42
# File 'lib/talk_to_your_app/plugin.rb', line 38

def tools(*tool_classes)
  @tools ||= []
  @tools.concat(tool_classes) unless tool_classes.empty?
  @tools
end

.validate_enablement!(_options) ⇒ Object

Per-plugin boot validation hook, called with the operator’s enablement options (e.g. { adapter: :sidekiq }). Override to enforce plugin-specific requirements; the default is a no-op.



55
56
# File 'lib/talk_to_your_app/plugin.rb', line 55

def validate_enablement!(_options)
end