Module: Progress::MonitorableProgress

Included in:
Array, File, Hash, Integer
Defined in:
lib/progress-monitor.rb

Instance Method Summary collapse

Instance Method Details

#monitorable1(method_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/progress-monitor.rb', line 18

def monitorable1(method_name)
  module_eval{ 
    orig_name =  ('orig_' + method_name.to_s).to_sym

    eval "alias #{ orig_name } #{ method_name }"

    define_method(method_name) do |&block|
    if Progress.active?
      progress_meter = Progress.add_progress_meter(self.monitor_size) if Progress.monitor?
      announcement   = Progress.get_announcement                      if Progress.announce?

      monitor_step = nil unless defined? monitor_step

      res = self.send(orig_name.to_sym) {|v| 
        progress_meter.tick(monitor_step)               if progress_meter 
        Progress.print_announcement(announcement.call(v))         if announcement
        block.call(v) 
      }

      Progress.remove_last_meter
      res
    else
      self.send(orig_name.to_sym) {|v| block.call(v)}
    end

    end
  }
end

#monitorable2(method_name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/progress-monitor.rb', line 47

def monitorable2(method_name)
  module_eval{ 
    orig_name =  ('orig_' + method_name.to_s).to_sym

    eval "alias #{ orig_name } #{ method_name }"

    define_method(method_name) do |&block|
    if Progress.active?
      progress_meter = Progress.add_progress_meter(self.monitor_size) if Progress.monitor?
      announcement   = Progress.get_announcement                      if Progress.announce?

      monitor_step = nil unless defined? monitor_step

      res = self.send(orig_name.to_sym) {|v1,v2| 
        progress_meter.tick(monitor_step) if progress_meter 
        Progress.print_announcement(announcement.call(v1,v2))         if announcement
        block.call(v1,v2);
      }

      Progress.remove_last_meter
      res
    else
      self.send(orig_name.to_sym) {|v1,v2| block.call(v1,v2) }
    end

    end
  }
end