Class: IRails::Command

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/irails/command.rb', line 6

def initialize(args)
  @args = args

  ipython_dir = ENV['IPYTHONDIR'] || '~/.ipython'
  @args.each do |arg|
    ipython_dir = $1 if arg =~ /\A--ipython-dir=(.*)\Z/
  end
  @kernel_dir = File.join(File.expand_path(ipython_dir), 'kernels', 'rails')
  @kernel_file = File.join(@kernel_dir, 'kernel.json')
  @irails_path = File.expand_path $0

  require './config/boot'
  require './config/application'

  Rails.application.require_environment!
end

Instance Method Details

#runObject



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

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