Sha256: 8745021b008f95359b4f1e9e5bdebbaf5d73de979802b85b6cda494770db8b87

Contents?: true

Size: 924 Bytes

Versions: 11

Compression:

Stored size: 924 Bytes

Contents

require 'singleton'

class PryMoves::Watch

  include Singleton

  attr_reader :list

  def initialize
    @list = Set.new
  end

  def process_cmd(cmd, binding_)
    case cmd
      when nil, ''
        if @list.count > 0
          print binding_
        else
          puts "Watch list is empty"
        end
      when '-clear', '-c'
        @list.clear
      else
        add cmd, binding_
    end
  end

  def add(cmd, binding_)
    @list << cmd
    puts eval_cmd(cmd, binding_)
  end

  def print(binding_)
    puts output(binding_) if @list.count > 0
  end

  def output(binding_)
    @list.map do |cmd|
      eval_cmd(cmd, binding_)
    end.join "; "
  end

  def eval_cmd(cmd, binding_)
    "\033[1m#{cmd}\033[0m: #{format binding_.eval(cmd)}"
  rescue NameError
    "\033[1m#{cmd}\033[0m: <undefined>"
  end

  def format(text)
    Pry::ColorPrinter.pp(text, "").strip
  end

  def empty?
    @list.empty?
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pry-moves-0.1.13 lib/pry-moves/watch.rb
pry-moves-0.1.12 lib/pry-moves/watch.rb
pry-moves-0.1.10 lib/pry-moves/watch.rb
pry-moves-0.1.9 lib/pry-moves/watch.rb
pry-moves-0.1.8 lib/pry-moves/watch.rb
pry-moves-0.1.7 lib/pry-moves/watch.rb
pry-moves-0.1.6 lib/pry-moves/watch.rb
pry-moves-0.1.5 lib/pry-moves/watch.rb
pry-moves-0.1.4 lib/pry-moves/watch.rb
pry-moves-0.1.3 lib/pry-moves/watch.rb
pry-moves-0.1.2 lib/pry-moves/watch.rb