Module: Alchemy::Modules

Included in:
BaseController
Defined in:
lib/alchemy/modules.rb

Constant Summary collapse

@@alchemy_modules =
YAML.load_file(File.expand_path('../../../config/alchemy/modules.yml', __FILE__))

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/alchemy/modules.rb', line 7

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'
}


24
25
26
# File 'lib/alchemy/modules.rb', line 24

def self.register_module(module_definition)
  @@alchemy_modules << module_definition.stringify_keys
end

Instance Method Details

#module_definition_for(name) ⇒ 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



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/alchemy/modules.rb', line 33

def module_definition_for(name)
  case name
  when String
    alchemy_modules.detect { |p| p['name'] == name }
  when Hash
    alchemy_modules.detect do |alchemy_module|
      definition_from_subnavi(alchemy_module, name.symbolize_keys)
    end
  else
    raise ArgumentError, "Could not find module definition for #{name}"
  end
end