Class: EYCli::CommandManager
- Inherits:
-
Object
- Object
- EYCli::CommandManager
- Defined in:
- lib/ey_cli/command_manager.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize ⇒ CommandManager
constructor
A new instance of CommandManager.
- #load_command(name) ⇒ Object
- #register_command(*names) ⇒ Object
Constructor Details
#initialize ⇒ CommandManager
Returns a new instance of CommandManager.
4 5 6 7 |
# File 'lib/ey_cli/command_manager.rb', line 4 def initialize @commands = {} register_command :accounts, :apps, :console, :create_app, :create_env, :deploy, :help, :show end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
3 4 5 |
# File 'lib/ey_cli/command_manager.rb', line 3 def commands @commands end |
Instance Method Details
#[](name) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/ey_cli/command_manager.rb', line 15 def [](name) command_name = name.to_sym return nil unless commands.key?(command_name) commands[command_name] = load_command(command_name) unless commands[command_name] commands[command_name] end |
#load_command(name) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ey_cli/command_manager.rb', line 22 def load_command(name) const_name = name.to_s.capitalize.gsub(/_(.)/) { $1.upcase } if EYCli::Command.const_defined?(const_name) EYCli::Command.const_get(const_name).new # TODO: else require and retry (PLUGINS) end end |
#register_command(*names) ⇒ Object
9 10 11 12 13 |
# File 'lib/ey_cli/command_manager.rb', line 9 def register_command(*names) names.each do | name | commands[name] = false end end |