Class: Shell::Initializer
- Inherits:
-
Object
- Object
- Shell::Initializer
- Defined in:
- lib/crane/shell_initializer.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
Instance Method Summary collapse
- #command_exist?(command = false) ⇒ Boolean
- #get_command ⇒ Object
- #get_command_file(command = false) ⇒ Object
- #inexistent_command ⇒ Object
-
#initialize(argv) ⇒ Initializer
constructor
A new instance of Initializer.
- #run ⇒ Object
- #run_command(command, args = []) ⇒ Object
- #should_exit? ⇒ Boolean
Constructor Details
#initialize(argv) ⇒ Initializer
Returns a new instance of Initializer.
10 11 12 13 14 |
# File 'lib/crane/shell_initializer.rb', line 10 def initialize argv @args = argv get_command run end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
8 9 10 |
# File 'lib/crane/shell_initializer.rb', line 8 def command @command end |
Instance Method Details
#command_exist?(command = false) ⇒ Boolean
34 35 36 |
# File 'lib/crane/shell_initializer.rb', line 34 def command_exist? command = false File.exists? get_command_file(command) end |
#get_command ⇒ Object
30 31 32 |
# File 'lib/crane/shell_initializer.rb', line 30 def get_command @command = Shell::Parser::get_command @args end |
#get_command_file(command = false) ⇒ Object
38 39 40 41 |
# File 'lib/crane/shell_initializer.rb', line 38 def get_command_file command = false command = @command unless command File.("../commands/" + command + ".rb", __FILE__) end |
#inexistent_command ⇒ Object
51 52 53 |
# File 'lib/crane/shell_initializer.rb', line 51 def inexistent_command @command_obj = Crane::Engine.new(@args) end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/crane/shell_initializer.rb', line 16 def run if @command if command_exist? require get_command_file return run_command @command end end inexistent_command end |
#run_command(command, args = []) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/crane/shell_initializer.rb', line 43 def run_command command, args = [] command = @command unless command return inexistent_command unless command_exist?(command) require get_command_file(command) command = command.capitalize @command_obj = Crane::Commands.const_get(command).new(@args) end |
#should_exit? ⇒ Boolean
26 27 28 |
# File 'lib/crane/shell_initializer.rb', line 26 def should_exit? return false || true unless @command end |