Class: RorchadoGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/rorchado/rorchado_generator.rb

Instance Method Summary collapse

Instance Method Details

#GeneratorHandlerObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rails/generators/rorchado/rorchado_generator.rb', line 26

def GeneratorHandler
  command = "#{command_name}".downcase
  module_name = "#{options.module}".downcase

  #Debug
  #puts "Command: #{command}" 
  #puts "Modules: #{module_name}"

  # Check if the command is valid
  if !@valid_commands.include?( command ) then
    puts "The command '#{command}' is not supported by RoRChado gem."
  elsif command=="help" then
    puts "List of available commands:"
    @valid_commands.each do |command|
      puts " - #{command} , e.g. rails g rorchado #{command} [OPTIONS]"
    end
  elsif command=="list" then
    puts "List of available Chado modules:"
    @valid_modules.each do |module_tmp|
      puts " - #{module_tmp}"
    end      
  else
    # Check which module to handle
    if module_name == "all" then
      # create an array with all the modules
      @valid_modules.each do |module_tmp|
        send("#{command.capitalize}Module" , module_tmp )
      end
    else
      # handle the requested and valid module        
      found = false
      @valid_modules.each do |module_tmp|
        if module_tmp == module_name then
          found = true
          break
        end
      end

      if found then
        send("#{command.capitalize}Module" , module_name )
      else
        # Check if requested to install/unistall the admin
        if module_name == "admin"  then
          send("#{command.capitalize}Admin")
        else
          puts "The module '#{module_name}' is not supported by RoRChado gem."
        end
      end

    end
  end   
end

#initObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rails/generators/rorchado/rorchado_generator.rb', line 11

def init
  # Read the available modules from the XML file
  xml = File.read(self.class.source_root + '/db_schemas/chado_schema.xml')    
  @docxml = Hpricot::XML(xml)
  
  @valid_modules = []

  (@docxml/:modules/:module).each do |module_item|      
    @valid_modules << (module_item.get_attribute :id)
  end
    
  @valid_commands = [ "help" , "list" , "install" , "uninstall" ]  
end