module Pico::PryContext

Attributes

commands_defined[R]

Public Instance Methods

define_commands() click to toggle source
# File lib/pico/pry_context.rb, line 20
def define_commands
  define_reload_command
  define_rake_command
  define_tmux_command if ENV['TMUX']
  @commands_defined = true
end
define_rake_command() click to toggle source
# File lib/pico/pry_context.rb, line 36
def define_rake_command
  Pry::Commands.create_command "rake", keep_retval: true do
    description "Run the test suite"

    def process
      build_passed = Pico::TestRunner.run!
      operator = args.shift
      command = args.shift
      evaluate_hook(build_passed, operator, command, args) if operator
      build_passed
    end

    def evaluate_hook(build_passed, operator, command, args)
      if operator == '&&'
        run(command, args) if build_passed
      elsif operator == '||'
        run(command, args) unless build_passed
      else
        raise ArgumentError, "Must supply either '&&' or '||' operators, followed by a pry command"
      end
    end
  end

  def define_tmux_command
    Pry::Commands.create_command "tmux" do
      description "Run a tmux command"

      def process
        system 'tmux', *args
      end
    end
  end
end
define_reload_command() click to toggle source
# File lib/pico/pry_context.rb, line 27
def define_reload_command
  Pry::Commands.block_command "reload!", "Reload #{Pico.application.name}" do
    puts "Reloading #{Pico.application.name}..."
    Pico.application.reload!
    _pry_.binding_stack.push Pico.application.mod.__binding__
    _pry_.binding_stack.shift until _pry_.binding_stack.size == 1
  end
end
define_tmux_command() click to toggle source
# File lib/pico/pry_context.rb, line 59
def define_tmux_command
  Pry::Commands.create_command "tmux" do
    description "Run a tmux command"

    def process
      system 'tmux', *args
    end
  end
end
evaluate_hook(build_passed, operator, command, args) click to toggle source
# File lib/pico/pry_context.rb, line 48
def evaluate_hook(build_passed, operator, command, args)
  if operator == '&&'
    run(command, args) if build_passed
  elsif operator == '||'
    run(command, args) unless build_passed
  else
    raise ArgumentError, "Must supply either '&&' or '||' operators, followed by a pry command"
  end
end
process() click to toggle source
# File lib/pico/pry_context.rb, line 40
def process
  build_passed = Pico::TestRunner.run!
  operator = args.shift
  command = args.shift
  evaluate_hook(build_passed, operator, command, args) if operator
  build_passed
end
start!() click to toggle source
# File lib/pico/pry_context.rb, line 11
def start!
  if Pico.application.booted?
    raise Error, "cannot start pry context if application has booted"
  end
  define_commands unless commands_defined
  Pico.boot!
  Pico.application.mod.pry
end