Class: IRuby::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/iruby/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
11
12
# File 'lib/iruby/command.rb', line 5

def initialize(args)
  @args = args

  @ipython_dir = File.expand_path("~/.ipython")
  @kernel_dir = resolve_kernelspec_dir.freeze
  @kernel_file = File.join(@kernel_dir, 'kernel.json').freeze
  @iruby_path = File.expand_path $0
end

Instance Attribute Details

#ipython_dirObject (readonly)

Returns the value of attribute ipython_dir.



14
15
16
# File 'lib/iruby/command.rb', line 14

def ipython_dir
  @ipython_dir
end

#kernel_dirObject (readonly)

Returns the value of attribute kernel_dir.



14
15
16
# File 'lib/iruby/command.rb', line 14

def kernel_dir
  @kernel_dir
end

#kernel_fileObject (readonly)

Returns the value of attribute kernel_file.



14
15
16
# File 'lib/iruby/command.rb', line 14

def kernel_file
  @kernel_file
end

Instance Method Details

#ipython_kernel_dirObject



16
17
18
# File 'lib/iruby/command.rb', line 16

def ipython_kernel_dir
  File.join(File.expand_path(@ipython_dir), 'kernels', 'ruby')
end

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/iruby/command.rb', line 20

def run
  case @args.first
  when 'version', '-v', '--version'
    require 'iruby/version'
    puts "IRuby #{IRuby::VERSION}, Ruby #{RUBY_VERSION}"
  when 'help', '-h', '--help'
    print_help
  when 'register'
    force_p = @args.include?('--force')
    if registered_iruby_path && !force_p
      STDERR.puts "#{@kernel_file} already exists!\nUse --force to force a register."
      exit 1
    end
    register_kernel(force_p)
  when 'unregister'
    unregister_kernel
  when 'kernel'
    run_kernel
  else
    run_ipython
  end
end