Module: Mimi::Core::Module::ClassMethods

Defined in:
lib/mimi/core/module.rb

Instance Method Summary collapse

Instance Method Details

#configure(opts = {}) ⇒ Object

Processes given values for configurable parameters defined in the module manifest and populates the options Hash.

Parameters:

  • opts (Hash) (defaults to: {})

    values for configurable parameters



23
24
25
26
27
28
29
# File 'lib/mimi/core/module.rb', line 23

def configure(opts = {})
  manifest_hash = manifest
  unless manifest_hash.is_a?(Hash)
    raise "#{self}.manifest should be implemented and return Hash"
  end
  @options = Mimi::Core::Manifest.new(manifest_hash).apply(opts)
end

#manifestHash

Module manifest

Mimi modules overload this method to define their own set of configurable parameters. The method should return a Hash representation of the manifest.

NOTE: to avoid clashes with other modules, it is advised that configurable parameters for the module have some module-specific prefix. E.g. Mimi::DB module has its configurable parameters names as db_adapter, db_database, db_username and so on.

Returns:

See Also:



69
70
71
# File 'lib/mimi/core/module.rb', line 69

def manifest
  {}
end

#module_pathPathname, ...

Returns the path to module files, if the module exposes any files.

Some modules may expose its files to the application using Mimi core. For example, a module may contain some rake tasks with useful functionality.

To expose module files, this method must be overloaded and point to the root of the gem folder:

# For example, module my_lib folder and files:
/path/to/my_lib/
  ./lib/my_lib/...
  ./lib/my_lib.rb
  ./spec/spec_helper
  ...

# my_lib module should expose its root as .module_path: /path/to/my_lib

Returns:

  • (Pathname, String, nil)


52
53
54
# File 'lib/mimi/core/module.rb', line 52

def module_path
  nil
end

#optionsHash<Symbol,Object>

Returns a Hash of configurable parameter values accepted and set by the .configure method.

Returns:

  • (Hash<Symbol,Object>)


106
107
108
# File 'lib/mimi/core/module.rb', line 106

def options
  @options || {}
end

#startObject

Starts the module.

Mimi modules overload this method to implement some module-specific logic that should happen on application startup. E.g. mimi-messaging establishes a connection with a message broker and declares message consumers.



79
80
81
# File 'lib/mimi/core/module.rb', line 79

def start(*)
  @module_started = true
end

#started?true, false

Returns true if the module is started.

Returns:

  • (true, false)


87
88
89
# File 'lib/mimi/core/module.rb', line 87

def started?
  @module_started
end

#stopObject

Starts the module.

Mimi modules overload this method to implement some module-specific logic that should happen on application shutdown. E.g. mimi-messaging closes a connection with a message broker.



97
98
99
# File 'lib/mimi/core/module.rb', line 97

def stop(*)
  @module_started = false
end