Class: Nib::Console

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/nib/console.rb

Constant Summary collapse

IRBRC =
<<~'IRB'.freeze
  require \"rubygems\"
  require \"irb/completion\"
  require \"irb/ext/save-history\"
  # irb configuration
  IRB.conf[:PROMPT_MODE] = :SIMPLE
  IRB.conf[:AUTO_INDENT] = true
  # irb history
  IRB.conf[:EVAL_HISTORY] = 10
  IRB.conf[:SAVE_HISTORY] = 1000
  IRB.conf[:HISTORY_FILE] = \"#{Dir.pwd}/tmp/irb_history\"
IRB
PRYRC =
'Pry.config.history.file = \"#{Dir.pwd}/tmp/irb_history\"'.freeze
SCRIPT =
<<~SH.freeze
  echo '#{IRBRC}' > /root/.irbrc
  echo '#{PRYRC}' > /root/.pryrc
  has_pry=false
  has_boot=false
  if hash pry 2>/dev/null ; then
    has_pry=true
  fi
  if [ -f config/boot.rb ]; then
    has_boot=true
  fi
  if [ -f bin/console ]; then
    bin/console
  elif [ -f bin/rails ]; then
    rails console
  elif [ \\$has_boot = true ] && [ \\$has_pry = true ]; then
    pry -r ./config/boot
  elif [ \\$has_boot = true ]; then
    irb -r ./config/boot
  elif [ \\$has_pry = true ]; then
    bundle config console pry
    bundle console
  else
    bundle console
  fi
SH

Instance Method Summary collapse

Methods included from Command

included, #initialize

Instance Method Details

#executeObject



46
47
48
49
# File 'lib/nib/console.rb', line 46

def execute
  system('mkdir', '-p', './tmp')
  super
end

#scriptObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/nib/console.rb', line 51

def script
  @script ||= <<~SCRIPT
    docker-compose \
      run \
      --rm \
      -e HISTFILE=./tmp/shell_history \
      #{service} \
      #{command}
  SCRIPT
end