Class: Shell::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/crane/shell_initializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commandObject

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

Returns:

  • (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_commandObject



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.expand_path("../commands/" + command + ".rb", __FILE__)
end

#inexistent_commandObject



51
52
53
# File 'lib/crane/shell_initializer.rb', line 51

def inexistent_command
  @command_obj = Crane::Engine.new(@args)
end

#runObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/crane/shell_initializer.rb', line 26

def should_exit?
  return false || true unless @command
end