Module: Alchemy::Modules
- Included in:
- BaseController
- Defined in:
- lib/alchemy/modules.rb
Constant Summary collapse
- @@alchemy_modules =
YAML.load_file(File.('../../config/alchemy/modules.yml', __dir__))
Class Method Summary collapse
- .included(base) ⇒ Object
-
.register_module(module_definition) ⇒ Object
Register a Alchemy module.
Instance Method Summary collapse
-
#module_definition_for(name_or_params) ⇒ Object
Get the module definition for given module name.
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/alchemy/modules.rb', line 9 def self.included(base) base.send :helper_method, :alchemy_modules, :module_definition_for end |
.register_module(module_definition) ⇒ Object
Register a Alchemy module.
A module is a Hash that must have at least a name and a navigation key that has a controller and action name.
Example:
name: 'module',
navigation: {
controller: 'admin/controller_name',
action: 'index'
}
26 27 28 |
# File 'lib/alchemy/modules.rb', line 26 def self.register_module(module_definition) @@alchemy_modules << module_definition.deep_stringify_keys end |
Instance Method Details
#module_definition_for(name_or_params) ⇒ Object
Get the module definition for given module name
You can also pass a hash of an module definition. It then tries to find the module defintion from controller name and action name
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/alchemy/modules.rb', line 35 def module_definition_for(name_or_params) case name_or_params when String alchemy_modules.detect { |m| m['name'] == name_or_params } when Hash name_or_params.stringify_keys! alchemy_modules.detect do |alchemy_module| module_navi = alchemy_module.fetch('navigation', {}) definition_from_mainnavi(module_navi, name_or_params) || (module_navi, name_or_params) end else raise ArgumentError, "Could not find module definition for #{name_or_params}" end end |