Class: EventMachine::FS::Command

Inherits:
EM::SystemCommand
  • Object
show all
Defined in:
lib/em-fs/fs/command.rb

Constant Summary collapse

PROGRESS_REGEXP =
/([A-Za-z0-9\.\-\/]+)\n[ ]+(\d+)/.freeze

Instance Method Summary collapse

Instance Method Details

#execute(&block) ⇒ Object

Invokes ‘#execute` of super-class and adds a progress matcher.



10
11
12
13
14
15
16
17
18
# File 'lib/em-fs/fs/command.rb', line 10

def execute &block
  super &block

  stdout.match PROGRESS_REGEXP, match: :last, in: :output do |file, bytes|
    receive_progress file, bytes.to_i
  end

  self
end

#progress {|file, bytes| ... } ⇒ Object

Defines a progress callback.

Yields:

  • The block to be stored as callback for progress events.

Yield Parameters:

  • file (String)

    The file that´s been updated.

  • bytes (Integer)

    The bytes moved or copied.



40
41
42
# File 'lib/em-fs/fs/command.rb', line 40

def progress &block
  progress_callbacks << block
end

#receive_progress(file, bytes) ⇒ Object

Is called when ever a ‘EM::FilesystemCommand` stdout updates the line is matched the `EM::FilesystemCommand::PROGRESS_REGEXP`.

Calls all defined callbacks for progress events.

Parameters:

  • file (String)

    The file that´s been updated.

  • bytes (Integer)

    The bytes moved or copied.



28
29
30
31
32
# File 'lib/em-fs/fs/command.rb', line 28

def receive_progress file, bytes
  progress_callbacks.each do |cb|
    cb.call file, bytes
  end
end