Class: Uniword::Plugin::Registry

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

Overview

Central registry for installed plugins. Each plugin registers its extension surface (validator, transformer, cli command) by name; lookup is by name or by class.

Open/closed: new extension surfaces = new methods on this class. Existing entries untouched.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cli_commandsHash{Symbol => Plugin::CliCommand} (readonly)

Returns:



24
25
26
# File 'lib/uniword/plugin/registry.rb', line 24

def cli_commands
  @cli_commands
end

.transformersHash{Symbol => Plugin::Transformer} (readonly)

Returns:



21
22
23
# File 'lib/uniword/plugin/registry.rb', line 21

def transformers
  @transformers
end

.validatorsHash{Symbol => Plugin::Validator} (readonly)

Returns:



18
19
20
# File 'lib/uniword/plugin/registry.rb', line 18

def validators
  @validators
end

Class Method Details

.clearvoid

This method returns an undefined value.

Clear every registry. Used between tests and by Configuration#reset!.



75
76
77
78
79
# File 'lib/uniword/plugin/registry.rb', line 75

def clear
  @validators.clear
  @transformers.clear
  @cli_commands.clear
end

.register_cli_command(name, command_class) ⇒ void

This method returns an undefined value.

Register a CLI command (a Thor subclass).

Parameters:

  • name (Symbol)
  • command_class (Class)

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
68
69
# File 'lib/uniword/plugin/registry.rb', line 61

def register_cli_command(name, command_class)
  raise ArgumentError, "name must be a Symbol" unless name.is_a?(Symbol)
  unless command_class.is_a?(Class)
    raise ArgumentError,
          "command_class must be a Class"
  end

  @cli_commands[name] = command_class
end

.register_transformer(name, transformer) ⇒ void

This method returns an undefined value.

Register a transformer.

Parameters:

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
# File 'lib/uniword/plugin/registry.rb', line 46

def register_transformer(name, transformer)
  raise ArgumentError, "name must be a Symbol" unless name.is_a?(Symbol)
  unless transformer.is_a?(Transformer)
    raise ArgumentError,
          "transformer must be a Transformer"
  end

  @transformers[name] = transformer
end

.register_validator(name, validator) ⇒ void

This method returns an undefined value.

Register a validator. Append-only; duplicate name raises.

Parameters:

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
# File 'lib/uniword/plugin/registry.rb', line 31

def register_validator(name, validator)
  raise ArgumentError, "name must be a Symbol" unless name.is_a?(Symbol)
  unless validator.is_a?(Validator)
    raise ArgumentError,
          "validator must be a Validator"
  end

  @validators[name] = validator
end