Module: Mimi::Core

Included in:
Mimi
Defined in:
lib/mimi/core.rb,
lib/mimi/core/rake.rb,
lib/mimi/core/module.rb,
lib/mimi/core/struct.rb,
lib/mimi/core/version.rb,
lib/mimi/core/manifest.rb,
lib/mimi/core/inheritable_property.rb

Overview

Mimi::Core extends the Mimi namespace with its instance methods.

Defined Under Namespace

Modules: InheritableProperty, Module, Rake Classes: Manifest, Struct

Constant Summary collapse

VERSION =
'1.2.0'.freeze

Instance Method Summary collapse

Instance Method Details

#app_path_to(*args) ⇒ Pathname

Constructs the path relative to the application's root path.

Example: Mimi.app_root_path # => /path/to/my_app Mimi.app_path_to('app', 'models') # => /path/to/my_app/app/models

Parameters:

  • args (Array<String,Pathname>)

Returns:

  • (Pathname)


40
41
42
# File 'lib/mimi/core.rb', line 40

def app_path_to(*args)
  app_root_path.join(*args)
end

#app_root_pathPathname

Returns the application's root path.

The root path is the current working directory by default. If you need to use a different path as the app root path, use #app_root_path=()

Returns:

  • (Pathname)


18
19
20
# File 'lib/mimi/core.rb', line 18

def app_root_path
  @app_root_path ||= Pathname.pwd.expand_path
end

#app_root_path=(path) ⇒ Pathname

Sets the application's root path explicitly

Parameters:

  • path (String, Pathname)

Returns:

  • (Pathname)


27
28
29
# File 'lib/mimi/core.rb', line 27

def app_root_path=(path)
  @app_root_path = Pathname.new(path).expand_path
end

#loaded_modulesArray<Module>

Returns the list of loaded (require'd) modules

Returns:



63
64
65
# File 'lib/mimi/core.rb', line 63

def loaded_modules
  @loaded_modules ||= []
end

#loaded_modules_pathsArray<Pathname>

Returns all loaded module paths, which are defined (non nil)

Returns:



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

def loaded_modules_paths
  loaded_modules.map(&:module_path).reject(&:nil?)
end

#require_files(glob, root_path = app_root_path) ⇒ Object

Requires all files that match the glob.

Parameters:

  • glob (String)
  • root_path (Pathname, nil) (defaults to: app_root_path)

    if not specified, app_root_path will be used



88
89
90
91
92
# File 'lib/mimi/core.rb', line 88

def require_files(glob, root_path = app_root_path)
  Pathname.glob(root_path.join(glob)).each do |filename|
    require filename.expand_path
  end
end

#startObject

Starts all used modules in the ascending order



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

def start
  used_modules.each { |m| m.start unless m.started? }
end

#stopObject

Stops all used modules in the reversed order



102
103
104
# File 'lib/mimi/core.rb', line 102

def stop
  used_modules.reverse.each { |m| m.stop if m.started? }
end

#use(mod, opts = {}) ⇒ Object

Use the given module

Includes the module in the list of used Mimi modules. Used modules are automatically started/stopped when Mimi.start is performed, in the order of appending.

Parameters:

  • mod (Module)
  • opts (Hash, nil) (defaults to: {})

    optional parameters to be passed to the module's .configure method

Raises:

  • (ArgumentError)


52
53
54
55
56
57
# File 'lib/mimi/core.rb', line 52

def use(mod, opts = {})
  raise ArgumentError, "#{mod} is not a Mimi module" unless mod < Mimi::Core::Module
  mod.configure(opts)
  used_modules << mod unless used_modules.include?(mod)
  true
end

#used_modulesArray<Module>

Returns the list of used modules

Returns:



71
72
73
# File 'lib/mimi/core.rb', line 71

def used_modules
  @used_modules ||= []
end