em-systemcommand 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,12 +17,20 @@ module EventMachine
17
17
  @outputbuffer.string
18
18
  end
19
19
 
20
- # Convenience method to create a callback that matches a regular expression
20
+ ##
21
+ # Convenience method to create a callback that matches a regular
22
+ # expression
21
23
  def match regexp, opt = {}, &block
22
- opt = { in: :line }.merge opt
24
+ opt = { in: :line, match: :first }.merge opt
23
25
  (opt[:in] == :output ? receive_update_callbacks : receive_line_callbacks) << lambda do |data|
24
- if m = data.match(regexp)
25
- block.call m.to_a
26
+ matches = data.scan regexp
27
+ if matches.length > 0
28
+ case opt[:match]
29
+ when :first
30
+ block.call *matches[0]
31
+ when :last
32
+ block.call *matches[matches.length-1]
33
+ end
26
34
  end
27
35
  end
28
36
  end
@@ -122,6 +130,7 @@ module EventMachine
122
130
  end
123
131
  end
124
132
 
133
+ ##
125
134
  # Invoked when the connection is terminated. Calls
126
135
  # `unbind(@name)` on master.
127
136
  def unbind
@@ -1,5 +1,5 @@
1
1
  module Em
2
2
  module Systemcommand
3
- VERSION = "1.2.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -128,7 +128,7 @@ describe 'Pipe' do
128
128
  received = []
129
129
  EM.run do
130
130
  EM::SystemCommand.execute 'echo "-123-"; echo "-456-"' do |on|
131
- on.stdout.match /-([0-9]+)-/, in: :line do |match, number|
131
+ on.stdout.match /-([0-9]+)-/, in: :line do |number|
132
132
  received << number
133
133
  end
134
134
 
@@ -144,7 +144,7 @@ describe 'Pipe' do
144
144
  received = []
145
145
  EM.run do
146
146
  EM::SystemCommand.execute %q{ruby -e '$stdout.sync = true; print "-123-\r"; sleep 0.1; print "-456-\r"; exit 0'} do |on|
147
- on.stdout.match /-([0-9]+)-/, in: :output do |match, number|
147
+ on.stdout.match /-([0-9]+)-/, in: :output do |number|
148
148
  received << number
149
149
  end
150
150
 
@@ -155,5 +155,22 @@ describe 'Pipe' do
155
155
  end
156
156
  end
157
157
  end
158
+
159
+ it 'should match last occurence on receive_update' do
160
+ received = []
161
+ EM.run do
162
+ EM::SystemCommand.execute %q{ruby -e '$stdout.sync = true; print "-123-\n"; sleep 0.1; print "-456-\n"; exit 0'} do |on|
163
+ on.stdout.match /-([0-9]+)-/, match: :last, in: :output do |number|
164
+ received << number
165
+ end
166
+
167
+ on.success do
168
+ EM.stop_event_loop
169
+ received.should == ["123","456"]
170
+ end
171
+ end
172
+ end
173
+ end
174
+
158
175
  end
159
176
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-systemcommand
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  segments:
165
165
  - 0
166
- hash: -3989779150220825362
166
+ hash: 1829514624315752226
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  none: false
169
169
  requirements:
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  segments:
174
174
  - 0
175
- hash: -3989779150220825362
175
+ hash: 1829514624315752226
176
176
  requirements: []
177
177
  rubyforge_project:
178
178
  rubygems_version: 1.8.24