Class | Bio::Shell::Setup
In: | lib/bio/shell/setup.rb
Parent: | Object

### Methods

check_ruby_version getoptlong install_savedir new setup_savedir

### Public Class methods

new()

[Source]

        # File lib/bio/shell/setup.rb, line 15
    15:   def initialize
    16:     check_ruby_version
    17:
    18:     # command line options
    19:     getoptlong
    20:
    21:     # setup working directory
    22:     savedir = setup_savedir
    23:
    24:     # load configuration and plugins
    25:     Bio::Shell.configure(savedir)
    26:
    27:     # set default to irb mode
    28:     Bio::Shell.cache[:mode] = @mode || :irb
    29:
    30:     case Bio::Shell.cache[:mode]
    31:     when :web
    32:       # setup rails server
    33:       Bio::Shell::Web.new
    34:     when :irb
    35:       # setup irb server
    36:       Bio::Shell::Irb.new
    37:     when :script
    38:       # run bioruby shell script
    39:       Bio::Shell::Script.new(@script)
    40:     end
    41:   end

### Public Instance methods

check_ruby_version()

[Source]

        # File lib/bio/shell/setup.rb, line 43
    43:   def check_ruby_version
    44:     if RUBY_VERSION < "1.8.2"
    45:       raise "BioRuby shell runs on Ruby version >= 1.8.2"
    46:     end
    47:   end

getoptlong()

command line argument (working directory or bioruby shell script file)

[Source]

        # File lib/bio/shell/setup.rb, line 50
    50:   def getoptlong
    51:     opts = GetoptLong.new
    52:     opts.set_options(
    53:       [ '--rails',   '-r',  GetoptLong::NO_ARGUMENT ],
    54:       [ '--web',     '-w',  GetoptLong::NO_ARGUMENT ],
    55:       [ '--console', '-c',  GetoptLong::NO_ARGUMENT ],
    56:       [ '--irb',     '-i',  GetoptLong::NO_ARGUMENT ]
    57:     )
    58:     opts.each_option do |opt, arg|
    59:       case opt
    60:       when /--rails/, /--web/
    61:         @mode = :web
    62:       when /--console/, /--irb/
    63:         @mode = :irb
    64:       end
    65:     end
    66:   end

install_savedir(savedir)

[Source]

         # File lib/bio/shell/setup.rb, line 105
    105:   def install_savedir(savedir)
    106:     FileUtils.makedirs(savedir)
    107:   end

setup_savedir()

[Source]

         # File lib/bio/shell/setup.rb, line 68
     68:   def setup_savedir
     69:     arg = ARGV.shift
     70:
     71:     # Options after the '--' argument are not parsed by GetoptLong and
     72:     # are passed to irb or rails.  This hack preserve the first option
     73:     # when working directory of the project is not given.
     74:     if arg and arg[/^-/]
     75:       ARGV.unshift arg
     76:       arg = nil
     77:     end
     78:
     79:     if arg.nil?
     80:       # run in the current directory
     81:       if File.exist?(Bio::Shell::Core::HISTORY)
     82:         savedir = Dir.pwd
     83:       else
     84:         savedir = File.join(ENV['HOME'].to_s, ".bioruby")
     85:         install_savedir(savedir)
     86:       end
     87:     elsif File.file?(arg)
     88:       # run file as a bioruby shell script
     89:       savedir = File.join(File.dirname(arg), "..")
     90:       @script = arg
     91:       @mode = :script
     92:     else
     93:       # run in new or existing directory
     94:       if arg[/^#{File::SEPARATOR}/]
     95:         savedir = arg
     96:       else
     97:         savedir = File.join(Dir.pwd, arg)
     98:       end
     99:       install_savedir(savedir)
    100:     end
    101:
    102:     return savedir
    103:   end

[Validate]