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
10 11 12 |
# File 'lib/alchemy/modules.rb', line 10 def 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'
}
27 28 29 30 31 |
# File 'lib/alchemy/modules.rb', line 27 def register_module(module_definition) definition_hash = module_definition.deep_stringify_keys @@alchemy_modules |= [definition_hash] 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/alchemy/modules.rb', line 39 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) || definition_from_nested(module_navi, name_or_params) end else raise ArgumentError, "Could not find module definition for #{name_or_params}" end end |