Module: MotherBrain::Gear

Defined in:
lib/mb/gear.rb,
lib/mb/gears/jmx.rb,
lib/mb/gears/mysql.rb,
lib/mb/gears/service.rb,
lib/mb/gears/jmx/action.rb,
lib/mb/gears/mysql/action.rb,
lib/mb/gears/service/action.rb,
lib/mb/gears/dynamic_service.rb,
lib/mb/gears/service/action_runner.rb

Overview

The base module for defining new Gears for a plugin. Any class including this module and registered with MotherBrain as a Gear will be available for use in the plugin DSL.

Gears represent the proverbial knobs and levers that can be used to manipulate a Component.

Examples:

Defining a new Gear


class Twitter < MB::Gear::Base
  register_gear :twitter
end

Plugin DSL usage


component "news_post" do

  twitter do
  ...
  end
end

Defined Under Namespace

Classes: Base, DynamicService, JMX, MySQL, Service

Constant Summary collapse

RESERVED_KEYWORDS =
[
  :name,
  :version,
  :description,
  :author,
  :email,
  :depends,
  :command,
  :component,
  :group,
  :execute
].freeze

Class Method Summary collapse

Class Method Details

.allSet<MotherBrain::Gear>

Return a Set containing all of the registered Gears that can be used within a MotherBrain plugin.

Returns:



85
86
87
# File 'lib/mb/gear.rb', line 85

def all
  @all ||= Set.new
end

.clear!Set

Clears all of the registered Gears.

Returns:

  • (Set)

    an empty Set



109
110
111
# File 'lib/mb/gear.rb', line 109

def clear!
  @all = Set.new
end

.element_name(klass) ⇒ Object



120
121
122
# File 'lib/mb/gear.rb', line 120

def element_name(klass)
  klass.keyword
end

.find_by_keyword(keyword) ⇒ MotherBrain::Gear?

Parameters:

  • keyword (Symbol)

Returns:



116
117
118
# File 'lib/mb/gear.rb', line 116

def find_by_keyword(keyword)
  all.find { |klass| klass.keyword == keyword }
end

.get_fun(klass) ⇒ Object



124
125
126
# File 'lib/mb/gear.rb', line 124

def get_fun(klass)
  element_name(klass)
end

.register(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Registers a given Class as a Gear to be used within MotherBrain plugins. This function is automatically called when MotherBrain::Gear is included into a Class. You probably don’t want to call this function directly.

Parameters:



75
76
77
78
79
# File 'lib/mb/gear.rb', line 75

def register(klass)
  validate_keyword(klass.keyword)

  all.add(klass)
end

.reload!Set<MotherBrain::Gear>

Clears all of the registered Gears and then traverses the ObjectSpace to find all classes which include MotherBrain::Gear and calls register with each.

Returns:



94
95
96
97
98
99
100
101
102
103
# File 'lib/mb/gear.rb', line 94

def reload!
  clear!
  ObjectSpace.each_object(::Module).each do |mod|
    if mod < MB::Gear
      register(mod)
    end
  end

  all
end