Module: Cloudit::Command

Defined in:
lib/cloudit/command.rb

Defined Under Namespace

Classes: Base, Generate, Index, Validate

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.commandsObject

Returns the value of attribute commands.



4
5
6
# File 'lib/cloudit/command.rb', line 4

def commands
  @commands
end

.descriptionsObject

Returns the value of attribute descriptions.



4
5
6
# File 'lib/cloudit/command.rb', line 4

def descriptions
  @descriptions
end

Class Method Details

.loadObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cloudit/command.rb', line 10

def self.load
  Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
    require file
    com = file.split('/')[-1].chomp('.rb')
    if com == 'index' || com == 'base'
      next
    end
    desc = Object.const_get("Cloudit::Command::#{com.capitalize}::DESCRIPTION")
    self.commands << com
    self.descriptions << {command: com, description: desc}
  end
end

.run(command, args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cloudit/command.rb', line 23

def self.run(command, args)
  begin
    if command.nil?
      command = 'index'
    elsif command == 'index'
      raise NameError if command == 'index'
    end
    klass = "Cloudit::Command::#{command.capitalize}"
    instance = Object.const_get(klass).new(args)
  rescue NameError
    $stdout.puts "cloudit: '#{command}' is not a cloudit command.\nSee 'cloudit --help' for usage."
    exit(1)
  end
  instance.execute
end

Instance Method Details

#commandsObject



39
40
41
# File 'lib/cloudit/command.rb', line 39

def commands
  self.class.commands
end

#descriptionsObject



43
44
45
# File 'lib/cloudit/command.rb', line 43

def descriptions
  self.class.descriptions
end