Class: PryMoves::Watch
- Inherits:
-
Object
- Object
- PryMoves::Watch
- Includes:
- Singleton
- Defined in:
- lib/pry-moves/watch.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Instance Method Summary collapse
- #add(cmd, binding_) ⇒ Object
- #empty? ⇒ Boolean
- #eval_cmd(cmd, binding_) ⇒ Object
- #format(text) ⇒ Object
-
#initialize ⇒ Watch
constructor
A new instance of Watch.
- #output(binding_) ⇒ Object
- #print(binding_) ⇒ Object
- #process_cmd(cmd, binding_) ⇒ Object
Constructor Details
#initialize ⇒ Watch
Returns a new instance of Watch.
10 11 12 |
# File 'lib/pry-moves/watch.rb', line 10 def initialize @list = Set.new end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
8 9 10 |
# File 'lib/pry-moves/watch.rb', line 8 def list @list end |
Instance Method Details
#add(cmd, binding_) ⇒ Object
29 30 31 32 |
# File 'lib/pry-moves/watch.rb', line 29 def add(cmd, binding_) @list << cmd puts eval_cmd(cmd, binding_) end |
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/pry-moves/watch.rb', line 56 def empty? @list.empty? end |
#eval_cmd(cmd, binding_) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/pry-moves/watch.rb', line 44 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 |
#format(text) ⇒ Object
52 53 54 |
# File 'lib/pry-moves/watch.rb', line 52 def format(text) Pry::ColorPrinter.pp(text, "").strip end |
#output(binding_) ⇒ Object
38 39 40 41 42 |
# File 'lib/pry-moves/watch.rb', line 38 def output(binding_) @list.map do |cmd| eval_cmd(cmd, binding_) end.join "; " end |
#print(binding_) ⇒ Object
34 35 36 |
# File 'lib/pry-moves/watch.rb', line 34 def print(binding_) puts output(binding_) if @list.count > 0 end |
#process_cmd(cmd, binding_) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pry-moves/watch.rb', line 14 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 |