Method: Command::DSL::CommandSetDefinition#require_commands
- Defined in:
- lib/command-set/dsl.rb
#require_commands(module_name, file = nil, path = [], *commands) ⇒ Object
If you’ve got a file dedicated to a set of commands, (and you really should) you can use require_commands to require it, call define_commands on a specific Module, pick out a specific subcommand (by passing a path), and then including specific commands from it.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/command-set/dsl.rb', line 48 def require_commands(module_name, file = nil, path = [], *commands) require file rescue nil module_path = module_name.to_s.split("::") mod = Object module_path.each do |part| mod = mod.const_get(part) end set = mod.define_commands set = set.find_command(*path) if CommandSet === set include_commands(set, *commands) elsif Class === set and Command > set command(set) else raise RuntimeError,"#{set.inspect} isn't a CommandSet or a Command" end end |