Skip to content

Commit 233f023

Browse files
committed
[rail_inspector] Extract Configuring::Document
In preparation for extracting more parsing behavior into this class and some related classes. Parsing is currently distributed in the individual checks, which makes them harder to test.
1 parent 1f8dc08 commit 233f023

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

tools/rail_inspector/lib/rail_inspector/configuring.rb

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "pathname"
44
require_relative "./configuring/check/general_configuration"
55
require_relative "./configuring/check/framework_defaults"
6+
require_relative "./configuring/document"
67

78
module RailInspector
89
class Configuring
@@ -43,29 +44,6 @@ def method_missing(name, ...)
4344
end
4445
end
4546

46-
class Doc
47-
attr_accessor :general_config, :versioned_defaults
48-
49-
def initialize(content)
50-
@before, @versioned_defaults, @general_config, @after =
51-
content
52-
.split("\n")
53-
.slice_before do |line|
54-
[
55-
"### Versioned Default Values",
56-
"### Rails General Configuration",
57-
"### Configuring Assets"
58-
].include?(line)
59-
end
60-
.to_a
61-
end
62-
63-
def to_s
64-
(@before + @versioned_defaults + @general_config + @after).join("\n") +
65-
"\n"
66-
end
67-
end
68-
6947
attr_reader :errors, :files
7048

7149
def initialize(rails_path)
@@ -88,7 +66,7 @@ def check
8866
end
8967

9068
def doc
91-
@doc ||= Configuring::Doc.new(files.doc_path.read)
69+
@doc ||= Configuring::Document.parse(files.doc_path.read)
9270
end
9371

9472
def rails_version
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
module RailInspector
4+
class Configuring
5+
class Document
6+
class << self
7+
def parse(text)
8+
before, versioned_defaults, general_config, after =
9+
text
10+
.split("\n")
11+
.slice_before do |line|
12+
[
13+
"### Versioned Default Values",
14+
"### Rails General Configuration",
15+
"### Configuring Assets"
16+
].include?(line)
17+
end
18+
.to_a
19+
20+
new(before, versioned_defaults, general_config, after)
21+
end
22+
end
23+
24+
attr_accessor :general_config, :versioned_defaults
25+
26+
def initialize(before, versioned_defaults, general_config, after)
27+
@before, @versioned_defaults, @general_config, @after =
28+
before, versioned_defaults, general_config, after
29+
end
30+
31+
def to_s
32+
(@before + @versioned_defaults + @general_config + @after).join("\n") +
33+
"\n"
34+
end
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)