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
-
#app_path_to(*args) ⇒ Pathname
Constructs the path relative to the application's root path.
-
#app_root_path ⇒ Pathname
Returns the application's root path.
-
#app_root_path=(path) ⇒ Pathname
Sets the application's root path explicitly.
-
#loaded_modules ⇒ Array<Module>
Returns the list of loaded (require'd) modules.
-
#loaded_modules_paths ⇒ Array<Pathname>
Returns all loaded module paths, which are defined (non nil).
-
#require_files(glob, root_path = app_root_path) ⇒ Object
Requires all files that match the glob.
-
#start ⇒ Object
Starts all used modules in the ascending order.
-
#stop ⇒ Object
Stops all used modules in the reversed order.
-
#use(mod, opts = {}) ⇒ Object
Use the given module.
-
#used_modules ⇒ Array<Module>
Returns the list of used modules.
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
40 41 42 |
# File 'lib/mimi/core.rb', line 40 def app_path_to(*args) app_root_path.join(*args) end |
#app_root_path ⇒ Pathname
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=()
18 19 20 |
# File 'lib/mimi/core.rb', line 18 def app_root_path @app_root_path ||= Pathname.pwd. end |
#app_root_path=(path) ⇒ Pathname
Sets the application's root path explicitly
27 28 29 |
# File 'lib/mimi/core.rb', line 27 def app_root_path=(path) @app_root_path = Pathname.new(path). end |
#loaded_modules ⇒ Array<Module>
Returns the list of loaded (require'd) modules
63 64 65 |
# File 'lib/mimi/core.rb', line 63 def loaded_modules @loaded_modules ||= [] end |
#loaded_modules_paths ⇒ Array<Pathname>
Returns all loaded module paths, which are defined (non nil)
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.
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. end end |
#start ⇒ Object
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 |
#stop ⇒ Object
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.
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 |