Module: Pry::Larry

Defined in:
lib/pry-larry/version.rb,
lib/pry-larry.rb

Defined Under Namespace

Classes: LarryCommand

Constant Summary collapse

VERSION =
"0.7.0"
MEMORY =
Hash.new{|h,k| h[k] = [] }
BEFORE_EVAL =
->(_, pry) do
  MEMORY[pry.hash].push Time.now.to_f
end
AFTER_EVAL =
->(input, pry) do
  walltime = (sprintf "%.2f", Time.now.to_f - MEMORY[pry.hash][-1]).to_f
  if input.nil? # Pry command
    pry.config.larry.speak_if.call(pry, walltime) and pry.config.larry.benchmark_commands and pry.config.larry.speaker.call(pry, walltime)
  else
    pry.config.larry.speak_if.call(pry, walltime) and pry.config.larry.speaker.call(pry, walltime)
  end
  MEMORY[pry.hash].clear
end
BEFORE_SESSION =
->(_,_, pry) do
  Pry::Larry.start(pry) if pry.config.larry.auto_start
end
AFTER_SESSION =
->(_, _, pry) do
  MEMORY.delete(pry.hash)
end

Class Method Summary collapse

Class Method Details

.start(pry) ⇒ Object Also known as: wakeup



23
24
25
26
27
28
29
# File 'lib/pry-larry.rb', line 23

def self.start(pry)
  if not pry.config.hooks.hook_exists? :before_eval, BEFORE_EVAL.hash
    pry.config.hooks.add_hook :before_eval, BEFORE_EVAL.hash, BEFORE_EVAL
    pry.config.hooks.add_hook :after_eval,  AFTER_EVAL.hash , AFTER_EVAL
    pry.config.hooks.add_hook :after_session, AFTER_SESSION.hash , AFTER_SESSION
  end
end

.stop(pry) ⇒ Object Also known as: chill



31
32
33
34
35
36
# File 'lib/pry-larry.rb', line 31

def self.stop(pry)
  pry.config.hooks.delete_hook :before_eval, BEFORE_EVAL.hash
  pry.config.hooks.delete_hook :after_eval , AFTER_EVAL.hash
  pry.config.hooks.delete_hook :after_session , AFTER_SESSION.hash
  MEMORY[pry.hash].clear
end