em-fs 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGQzZDIyMzlkZGEzZGVjZjUwNzEyM2IyMmU2N2Y4YTJkMjZlNGIwOQ==
4
+ OTM1Y2ZmNTM1Nzc0ZTMxYjkxMTViYzUyNGYwYTcwOTk5YjA5MzVhZQ==
5
5
  data.tar.gz: !binary |-
6
- YjE3MmY1NTI3YTc0NTE3MGIwM2VmY2M0YTZmZmUxYTY4ZTUwYWU4Yg==
6
+ NDE1YTI4ZmVhMWQ0ZTY1ZTdlYTE4NmRhMjFmYzQwYTliNDA1ODJmOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjdjYjdkZjQ0ZGJjMzUzM2MwMjRkOWEyOGM5OGUzZWM2NzBjOGE5Y2Q4NGFh
10
- NjFlYTA4OThkNTFlYTExY2NmMmQ2OWE2MjdjOWJjMDllNzU2NGNmOTVkYTE2
11
- ZDRmYjZjOTJkNDJlYzM2Y2RhYTUwNjk3MDlkODM3ODk2NTZmN2M=
9
+ MDM0ZDlkN2M0OWM5MmE2NDFiNDViMmY3M2EzYWFlMDkwNGFjMGRiYjA3NWUy
10
+ YWM5ZTFkZTMyNWVkZTZlYmNkNmJjNjIxOTZkMjc1Y2QxMGY1NDQ2MmM0ZmVj
11
+ YmVjZjczNTg2ZDUyMTY4MDc3OTMzNGRlYjIwNjcyNzc2MTZmOWE=
12
12
  data.tar.gz: !binary |-
13
- MThhMjNjYTc0NTI2OWI3MjQyZGQ3ZmY4ODc0YWQ5NThlYjExZmYyY2Q1OWQy
14
- MTRhNTUzMzE0ZTc4ZDg1NDc1ZDVhZWMzZDk4ODJjOTAyNjYwNTdjNmUwZDEz
15
- MjI0NWJmNmQ0ZjlkNDRmZThlYzEyZjMzNzJiMjU4Y2Q3NDIwYTI=
13
+ ZDkxMGNmZWQ3OWNhMDA0OWRlNzRiODc2MDMyOWRiNzRlYWM3NmZmOGRjYzg4
14
+ ZjBhNzgyZjdiZGYyZTU4MzE1ZWZiNjc0YzNjMTUxMTcyMmNlNzE4NWViN2Rl
15
+ MGY1Nzg0ZjkyMzU1OTU4NTFjZjkwMWQ0Yjg2ZmIyYjdhMWUxNmQ=
@@ -2,16 +2,24 @@
2
2
  module EventMachine
3
3
  class FS
4
4
  class Command < EM::SystemCommand
5
-
6
- PROGRESS_REGEXP = /([A-Za-z0-9\.,\-\/]+)\n[ ]+([^ ]+)/.freeze
5
+ PROGRESS_REGEXP = /([^\n]+)\n[ ]+([^ ]+)[ ]+(.+)%/.freeze
7
6
 
8
7
  ##
9
8
  # Invokes `#execute` of super-class and adds a progress matcher.
10
9
  def execute &block
11
10
  super &block
12
11
 
13
- stdout.match PROGRESS_REGEXP, match: :last, in: :output do |file, bytes|
14
- receive_progress file, bytes.gsub(/[^\d]/,'').to_i
12
+ last_progress = 0
13
+ last_progress_at = Time.new.to_f
14
+ stdout.match PROGRESS_REGEXP, match: :last, in: :output do |file, total_bytes, percentage|
15
+ progress = total_bytes.gsub(/[^\d]/,'').to_i
16
+ progress_at = Time.new.to_f
17
+ speed = (progress - last_progress) / (progress_at - last_progress_at)
18
+
19
+ receive_progress(file, progress, percentage.to_i, speed)
20
+
21
+ last_progress = progress
22
+ last_progress_at = progress_at
15
23
  end
16
24
 
17
25
  self
@@ -25,9 +33,9 @@ module EventMachine
25
33
  #
26
34
  # @param [String] file The file that´s been updated.
27
35
  # @param [Integer] bytes The bytes moved or copied.
28
- def receive_progress file, bytes
36
+ def receive_progress *args
29
37
  progress_callbacks.each do |cb|
30
- cb.call file, bytes
38
+ cb.call(*args)
31
39
  end
32
40
  end
33
41
 
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  class FS
3
- VERSION = "0.1.1"
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -1,15 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe EM::FS::RsyncCommand do
3
+ describe EM::FS::RsyncCommand, focus: true do
4
4
  context 'copying one file' do
5
5
  before :each do
6
6
  @source = File.join SPEC_ROOT, 'data', 'test'
7
7
  @target = File.join SPEC_ROOT, 'data', 'test.copy'
8
- @progress_updates = {}
8
+ @progress_updates = {}
9
+ @percentage_updates = {}
10
+ @speed_updates = {}
9
11
  EM.run do
10
12
  EM::FS.rsync @source, @target do |on|
11
- on.progress do |file, bytes|
12
- (@progress_updates[file] ||= []) << bytes
13
+ on.progress do |file, bytes, percentage, speed|
14
+ (@progress_updates[file] ||= []) << bytes
15
+ (@percentage_updates[file] ||= []) << percentage
16
+ (@speed_updates[file] ||= []) << speed
13
17
  end
14
18
 
15
19
  on.exit do |status|
@@ -32,6 +36,18 @@ describe EM::FS::RsyncCommand do
32
36
  @progress_updates['test'].length.should be > 0
33
37
  @progress_updates['test'].last.should == 102400
34
38
  end
39
+
40
+ it 'should track percentages' do
41
+ @percentage_updates.values.flatten.each do |percentage|
42
+ percentage.should be_a Integer
43
+ end
44
+ end
45
+
46
+ it 'should track speed' do
47
+ @speed_updates.values.flatten.each do |speed|
48
+ speed.should be_a Float
49
+ end
50
+ end
35
51
  end
36
52
 
37
53
  context 'copying multiple files' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Leonard Andersen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake