defmastership 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a98ba2cd70decfd584d57f914d05bc31356cd53846fa13b01f3406ff41dc087
4
- data.tar.gz: 999f28e56b654a6dd35d9da30a8701abd1121f62db4df730fcf903a255b34eff
3
+ metadata.gz: 9e81c3ab45ea06b43ad767d8ab89231e05eacca67dee259a8d968d515da6adb6
4
+ data.tar.gz: bb2abcc00dea06b45b35373eec37923236770310cd70842770be8d1ac92149e7
5
5
  SHA512:
6
- metadata.gz: 44bd90676d2ebd37cf47c0e6d9160340d1861497eb4a110e47e5b35c26cd23a28a1ddd24c93e489238520f916997fb2f45801ec1c74b84a7c44f16798b3c0eaf
7
- data.tar.gz: 60d4904b54cbb6708ff1633ad0d01d9e43a97d0e4cb90c51126487de2eae477e81e670db38fc151784bde3bb59f1f473abf804f08f0968f06d99dbd58a32c3fa
6
+ metadata.gz: 3df9a3fd838a4600b66690fd30fedcbf28b8e3af6d2afbe8d1ef813ea8b3b163b854f16ff3f219550a24b9624302ea0d32b8a043f90047070425d39e1b017cc4
7
+ data.tar.gz: 5b2b9c5105d548c2cba1571ad36830453bec01664d7ab4edec71a1132b30bb0651dd4d5a197f1d4c13a2a09d0ea9e69b2b0f3af975f0611de32b1cd52737c92d
data/lib/defmastership.rb CHANGED
@@ -6,6 +6,7 @@ require('defmastership/version')
6
6
  # Add requires for other files you add to your project here, so
7
7
  # you just need to require this one file in your bin file
8
8
  require('defmastership/constants')
9
+ require('defmastership/parsing_state')
9
10
  require('defmastership/definition')
10
11
  require('defmastership/definition_parser')
11
12
  require('defmastership/filters')
@@ -28,7 +28,7 @@ module DefMastership
28
28
  to_template: '',
29
29
  next_ref: 0
30
30
  }
31
- @in_literal = false
31
+ @parsing_state = ParsingState.new
32
32
  end
33
33
 
34
34
  def replace(method, line)
@@ -36,10 +36,10 @@ module DefMastership
36
36
  end
37
37
 
38
38
  def replace_refdef(line)
39
- if in_literal(line)
40
- line
41
- else
39
+ if @parsing_state.enabled?(line)
42
40
  do_replace_refdef(line)
41
+ else
42
+ line
43
43
  end
44
44
  end
45
45
 
@@ -78,10 +78,5 @@ module DefMastership
78
78
  def hmerge(match)
79
79
  @config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
80
80
  end
81
-
82
- def in_literal(line)
83
- @in_literal ^= true if line.chomp == '....'
84
- @in_literal
85
- end
86
81
  end
87
82
  end
@@ -0,0 +1,23 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Allow to know if we need to parse the line or simply ignore it
6
+ class ParsingState
7
+ def initialize
8
+ @last_disabling_line = nil
9
+ end
10
+
11
+ def enabled?(line)
12
+ line = line.dup.chomp
13
+ if ['....', '----'].include?(line)
14
+ if @last_disabling_line == line
15
+ @last_disabling_line = nil
16
+ elsif @last_disabling_line.nil?
17
+ @last_disabling_line = line
18
+ end
19
+ end
20
+ @last_disabling_line.nil?
21
+ end
22
+ end
23
+ end
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- VERSION = '1.0.12'
5
+ VERSION = '1.0.13'
6
6
  public_constant :VERSION
7
7
  end
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::ParsingState) do
7
+ subject(:parsing_state) do
8
+ described_class.new
9
+ end
10
+
11
+ describe '.new' do
12
+ it { is_expected.not_to(be(nil)) }
13
+ end
14
+
15
+ describe '#enabled_with?' do
16
+ context 'when starting' do
17
+ it { expect(parsing_state.enabled?("whatever\n")).to(eq(true)) }
18
+ it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
19
+ it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
20
+ it { expect(parsing_state.enabled?('....')).to(eq(false)) }
21
+ end
22
+
23
+ context 'when disabled' do
24
+ before { parsing_state.enabled?("----\n") }
25
+
26
+ it { expect(parsing_state.enabled?("whatever\n")).to(eq(false)) }
27
+ it { expect(parsing_state.enabled?("----\n")).to(eq(true)) }
28
+ it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
29
+ end
30
+
31
+ context 'with intricated disables satrting with "...."' do
32
+ before do
33
+ ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
34
+ end
35
+
36
+ it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
37
+ it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
38
+ end
39
+
40
+ context 'with intricated disables satrting with "----"' do
41
+ before do
42
+ ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
43
+ end
44
+
45
+ it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defmastership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérôme Arbez-Gindre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -216,6 +216,7 @@ files:
216
216
  - lib/defmastership/filters.rb
217
217
  - lib/defmastership/line_modifier_base.rb
218
218
  - lib/defmastership/modifier_base.rb
219
+ - lib/defmastership/parsing_state.rb
219
220
  - lib/defmastership/rename_included_files_line_modifier.rb
220
221
  - lib/defmastership/rename_included_files_modifier.rb
221
222
  - lib/defmastership/update_def_checksum_line_modifier.rb
@@ -234,6 +235,7 @@ files:
234
235
  - spec/unit/defmastership/definition_parser_spec.rb
235
236
  - spec/unit/defmastership/definition_spec.rb
236
237
  - spec/unit/defmastership/document_spec.rb
238
+ - spec/unit/defmastership/parsing_state_spec.rb
237
239
  - spec/unit/defmastership/rename_included_files_line_modifier_spec.rb
238
240
  - spec/unit/defmastership/rename_included_files_modifier_spec.rb
239
241
  - spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb