Sha256: 85ed43d73d61e8e0152ab321166293082989834f96024c598de8c9b24ec8a022

Contents?: true

Size: 987 Bytes

Versions: 16

Compression:

Stored size: 987 Bytes

Contents

require 'singleton'
require 'set'

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>"
  rescue => e
    "\033[1m#{cmd}\033[0m: <#{e}>"
  end

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

  def empty?
    @list.empty?
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pry-moves-1.0.15 lib/pry-moves/watch.rb
pry-moves-1.0.14 lib/pry-moves/watch.rb
pry-moves-1.0.13 lib/pry-moves/watch.rb
pry-moves-1.0.12 lib/pry-moves/watch.rb
pry-moves-1.0.11 lib/pry-moves/watch.rb
pry-moves-1.0.10 lib/pry-moves/watch.rb
pry-moves-1.0.9 lib/pry-moves/watch.rb
pry-moves-1.0.8 lib/pry-moves/watch.rb
pry-moves-1.0.7 lib/pry-moves/watch.rb
pry-moves-1.0.6 lib/pry-moves/watch.rb
pry-moves-1.0.5 lib/pry-moves/watch.rb
pry-moves-1.0.4 lib/pry-moves/watch.rb
pry-moves-1.0.3 lib/pry-moves/watch.rb
pry-moves-1.0.2 lib/pry-moves/watch.rb
pry-moves-1.0.1 lib/pry-moves/watch.rb
pry-moves-1.0.0 lib/pry-moves/watch.rb