cexpect 0.1.4 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edad159cd5db7b5838ff5f483242b93b0bdd20062e8d7b51c9f500a19e25b535
4
- data.tar.gz: eac146a9da3b515f422aa0b1dee779362b802649f0cedfff5fa703a4e03ee2a6
3
+ metadata.gz: 7d6f51d1822901ccaef277fd26017749f6d65ed3eaea50836fa2fbe5b7e90410
4
+ data.tar.gz: 9eade35e51126e2ce00f99a02f3f1052f09314ecd19b516cb51f0d7ea4438139
5
5
  SHA512:
6
- metadata.gz: 791c836396b9b0228dc79bd91f1f9467bd0846d344ae89d034ca87b910151307153da309239a0b17ee58deece2ad086bfa5b7b071c035c2105139ec172fa2bae
7
- data.tar.gz: 5413b0e772416590c42436b2783aea05cbc2af41f20a35d8c0d4225b814c60c3a92cc173b5c1d51d42ecd324c0492f7204752f1b89648491574fc841d6f1c6d8
6
+ metadata.gz: 28a4cc9e4edfa0b18fa6d57f0c43f0fefae54b8872de8fe09c56595b31bf203a0aa5a24fe8005ebc737483c5a7d5e293fdd1d95276a57faccb717e786420ddc1
7
+ data.tar.gz: 180e097fe5134c7527264a9a464bb5d4c27a8317dd08aef3886a560e997a00f1836f6740987fe6ccf83e8f181be8e5509f6a0ad2849b5788f89d9ac60312c1d6
@@ -24,9 +24,9 @@ jobs:
24
24
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
25
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
26
  # uses: ruby/setup-ruby@v1
27
- uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
27
+ uses: ruby/setup-ruby@v1.70.1
28
28
  with:
29
- ruby-version: 2.6
29
+ ruby-version: 3.0
30
30
  - name: Install dependencies
31
31
  run: bundle install
32
32
  - name: Run tests
data/Gemfile.lock CHANGED
@@ -1,33 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cexpect (0.1.3)
4
+ cexpect (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.0)
10
- diff-lcs (1.3)
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
11
  jaro_winkler (1.5.4)
12
- parallel (1.19.1)
13
- parser (2.7.1.1)
14
- ast (~> 2.4.0)
12
+ parallel (1.20.1)
13
+ parser (3.0.1.1)
14
+ ast (~> 2.4.1)
15
15
  rainbow (3.0.0)
16
16
  rake (12.3.3)
17
- rexml (3.2.4)
18
- rspec (3.9.0)
19
- rspec-core (~> 3.9.0)
20
- rspec-expectations (~> 3.9.0)
21
- rspec-mocks (~> 3.9.0)
22
- rspec-core (3.9.1)
23
- rspec-support (~> 3.9.1)
24
- rspec-expectations (3.9.1)
17
+ rexml (3.2.5)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.9.0)
27
- rspec-mocks (3.9.1)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.2)
28
28
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-support (3.9.2)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.2)
31
31
  rubocop (0.82.0)
32
32
  jaro_winkler (~> 1.5.1)
33
33
  parallel (~> 1.10)
@@ -36,9 +36,9 @@ GEM
36
36
  rexml
37
37
  ruby-progressbar (~> 1.7)
38
38
  unicode-display_width (>= 1.4.0, < 2.0)
39
- rubocop-rspec (1.38.1)
39
+ rubocop-rspec (1.41.0)
40
40
  rubocop (>= 0.68.1)
41
- ruby-progressbar (1.10.1)
41
+ ruby-progressbar (1.11.0)
42
42
  unicode-display_width (1.7.0)
43
43
 
44
44
  PLATFORMS
data/README.md CHANGED
@@ -69,6 +69,9 @@ rd = CExpect::Reader.new(orig_rd)
69
69
 
70
70
  wr.puts "Hello, World!\n"
71
71
  greeting = rd.fexpect("\n")
72
+
73
+ # If you want logging
74
+
72
75
  ```
73
76
 
74
77
  ## Development
data/lib/cexpect.rb CHANGED
@@ -15,11 +15,9 @@ module CExpect
15
15
  # expect method
16
16
  #
17
17
  class Reader < SimpleDelegator
18
- include Observable
19
-
20
- def initialize(_original)
21
- @leftovers = ''
22
- super
18
+ def initialize(io, observers = nil)
19
+ extend(LoggingReader) if observers
20
+ super(io)
23
21
  end
24
22
 
25
23
  def expect(pat, timeout = nil, match_method: :re_match)
@@ -45,22 +43,17 @@ module CExpect
45
43
  def expect_try(pat, buf, timeout, match_method)
46
44
  c = getc(timeout)
47
45
 
48
- if c.nil?
49
- @leftovers = buf
50
- throw(:result, nil)
51
- end
46
+ throw(:result, nil) if c.nil?
52
47
 
53
48
  buf << c
54
49
 
55
- log(pat, buf)
50
+ log(pat, buf) if respond_to?(:log)
56
51
 
57
52
  result = send(match_method, buf, pat)
58
53
  throw(:result, result) if result
59
54
  end
60
55
 
61
56
  def getc(timeout)
62
- return @leftovers.slice!(0).chr unless @leftovers.empty?
63
-
64
57
  rd = __getobj__
65
58
 
66
59
  return nil if !IO.select([rd], nil, nil, timeout) || eof?
@@ -68,13 +61,6 @@ module CExpect
68
61
  rd.getc.chr
69
62
  end
70
63
 
71
- def log(pat, buf)
72
- return if count_observers.zero?
73
-
74
- changed
75
- notify_observers(pat, buf)
76
- end
77
-
78
64
  def re_match(buf, pat)
79
65
  buf.match(pat)
80
66
  end
@@ -83,4 +69,18 @@ module CExpect
83
69
  buf[0, buf.size - pat.size] if buf.end_with?(pat)
84
70
  end
85
71
  end
72
+
73
+ #
74
+ # Adds logging capability when observers are given to constructor
75
+ #
76
+ module LoggingReader
77
+ include Observable
78
+
79
+ def log(pat, buf)
80
+ return if count_observers.zero?
81
+
82
+ changed
83
+ notify_observers(pat, buf)
84
+ end
85
+ end
86
86
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CExpect
4
- VERSION = '0.1.4'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cexpect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christer Jansson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-03 00:00:00.000000000 Z
11
+ date: 2021-05-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An expect method with more reasonable return values and logging functionality
14
14
  email:
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 3.1.2
59
+ rubygems_version: 3.1.6
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: An improved expect method