Module: Lita::Registry::Mixins

Included in:
Lita, Lita::Registry
Defined in:
lib/lita/registry.rb

Overview

Allows a registry to be added to another object.

Since:

  • 4.0.0

Instance Method Summary collapse

Instance Method Details

#adaptersHash

A registry of adapters.

Since:

  • 4.0.0


22
23
24
# File 'lib/lita/registry.rb', line 22

def adapters
  @adapters ||= {}
end

#configLita::Configuration

The primary configuration object. Provides user settings for the robot.

Since:

  • 4.0.0


9
10
11
# File 'lib/lita/registry.rb', line 9

def config
  @config ||= DefaultConfiguration.new(self).build
end

#configure {|config| ... } ⇒ void

This method returns an undefined value.

Yields the configuration object. Called by the user in a lita_config.rb file.

Yield Parameters:

Since:

  • 4.0.0


16
17
18
# File 'lib/lita/registry.rb', line 16

def configure
  yield config
end

#handlersSet

A registry of handlers.

Since:

  • 4.0.0


28
29
30
# File 'lib/lita/registry.rb', line 28

def handlers
  @handlers ||= Set.new
end

#hooksHash

A registry of hook handler objects.

Since:

  • 3.2.0


35
36
37
# File 'lib/lita/registry.rb', line 35

def hooks
  @hooks ||= Hash.new { |h, k| h[k] = Set.new }
end

#register_adapter(key, adapter) ⇒ void #register_adapter(key) { ... } ⇒ void

Overloads:

  • #register_adapter(key, adapter) ⇒ void

    This method returns an undefined value.

    Adds an adapter to the registry under the provided key.

  • #register_adapter(key) { ... } ⇒ void

    This method returns an undefined value.

    Adds an adapter to the registry under the provided key.

    Yields:

    • The body of the adapter class.

    Since:

    • 4.0.0

Since:

  • 4.0.0


50
51
52
53
54
55
56
57
58
# File 'lib/lita/registry.rb', line 50

def register_adapter(key, adapter = nil, &block)
  adapter = PluginBuilder.new(key, &block).build_adapter if block

  unless adapter.is_a?(Class)
    raise ArgumentError, I18n.t("lita.core.register_adapter.block_or_class_required")
  end

  adapters[key.to_sym] = adapter
end

#register_handler(handler) ⇒ void #register_handler(key) { ... } ⇒ void

Overloads:

  • #register_handler(handler) ⇒ void

    This method returns an undefined value.

    Adds a handler to the registry.

  • #register_handler(key) { ... } ⇒ void

    This method returns an undefined value.

    Adds a handler to the registry.

    Yields:

    • The body of the handler class.

    Since:

    • 4.0.0

Since:

  • 4.0.0


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/lita/registry.rb', line 70

def register_handler(handler_or_key, &block)
  if block
    handler = PluginBuilder.new(handler_or_key, &block).build_handler
  else
    handler = handler_or_key

    unless handler.is_a?(Class)
      raise ArgumentError, I18n.t("lita.core.register_handler.block_or_class_required")
    end
  end

  handlers << handler
end

#register_hook(name, hook) ⇒ void

This method returns an undefined value.

Adds a hook handler object to the registry for the given hook.

Since:

  • 3.2.0


87
88
89
# File 'lib/lita/registry.rb', line 87

def register_hook(name, hook)
  hooks[name.to_s.downcase.strip.to_sym] << hook
end

#resetvoid

This method returns an undefined value.

Clears the configuration object and the adapter, handler, and hook registries.

Since:

  • 3.2.0


94
95
96
97
98
99
# File 'lib/lita/registry.rb', line 94

def reset
  reset_adapters
  reset_config
  reset_handlers
  reset_hooks
end

#reset_adaptersvoid

This method returns an undefined value.

Resets the adapter registry, removing all registered adapters.

Since:

  • 3.2.0


104
105
106
# File 'lib/lita/registry.rb', line 104

def reset_adapters
  @adapters = nil
end

#reset_configvoid Also known as: clear_config

This method returns an undefined value.

Resets the configuration object. The next call to #config will create a fresh config object.

Since:

  • 4.0.0


111
112
113
# File 'lib/lita/registry.rb', line 111

def reset_config
  @config = nil
end

#reset_handlersvoid

This method returns an undefined value.

Resets the handler registry, removing all registered handlers.

Since:

  • 3.2.0


119
120
121
# File 'lib/lita/registry.rb', line 119

def reset_handlers
  @handlers = nil
end

#reset_hooksvoid

This method returns an undefined value.

Resets the hooks registry, removing all registered hook handlers.

Since:

  • 3.2.0


126
127
128
# File 'lib/lita/registry.rb', line 126

def reset_hooks
  @hooks = nil
end