pragmater 7.0.1 → 8.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{LICENSE.md → LICENSE.adoc} +29 -30
- data/README.adoc +323 -0
- data/bin/pragmater +5 -4
- data/lib/pragmater.rb +16 -4
- data/lib/pragmater/cli/helper.rb +40 -0
- data/lib/pragmater/cli/options/assembler.rb +45 -0
- data/lib/pragmater/cli/options/configuration.rb +37 -0
- data/lib/pragmater/cli/options/core.rb +56 -0
- data/lib/pragmater/cli/options/defaults.yml +6 -0
- data/lib/pragmater/cli/options/insert_remove.rb +38 -0
- data/lib/pragmater/cli/options/merger.rb +52 -0
- data/lib/pragmater/cli/shell.rb +63 -0
- data/lib/pragmater/context.rb +14 -0
- data/lib/pragmater/formatters/general.rb +34 -0
- data/lib/pragmater/formatters/main.rb +26 -0
- data/lib/pragmater/formatters/shebang.rb +25 -0
- data/lib/pragmater/identity.rb +5 -15
- data/lib/pragmater/parsers/comments.rb +30 -0
- data/lib/pragmater/parsers/file.rb +32 -0
- data/lib/pragmater/processors/handler.rb +25 -0
- data/lib/pragmater/processors/inserter.rb +24 -0
- data/lib/pragmater/processors/remover.rb +24 -0
- data/lib/pragmater/runner.rb +13 -16
- metadata +72 -58
- metadata.gz.sig +0 -0
- data/README.md +0 -263
- data/lib/pragmater/cli.rb +0 -124
- data/lib/pragmater/commenter.rb +0 -32
- data/lib/pragmater/formatter.rb +0 -59
- data/lib/pragmater/writer.rb +0 -69
data/lib/pragmater/writer.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Pragmater
|
4
|
-
# Writes formatted pragma comments to source file.
|
5
|
-
# :reek:TooManyInstanceVariables
|
6
|
-
# :reek:MissingSafeMethod
|
7
|
-
class Writer
|
8
|
-
# rubocop:disable Metrics/ParameterLists
|
9
|
-
def initialize file_path, new_comments, formatter: Formatter, commenter: Commenter
|
10
|
-
@file_path = file_path
|
11
|
-
@file_lines = File.readlines file_path
|
12
|
-
@formatter = formatter
|
13
|
-
@commenter = commenter
|
14
|
-
@old_comments = file_comments
|
15
|
-
@new_comments = new_comments
|
16
|
-
end
|
17
|
-
# rubocop:enable Metrics/ParameterLists
|
18
|
-
|
19
|
-
def add
|
20
|
-
comments = format commenter.new(old_comments, new_comments).add
|
21
|
-
lines = comments + file_lines_without_comments
|
22
|
-
insert_spacing! lines, comments
|
23
|
-
write { lines.join }
|
24
|
-
end
|
25
|
-
|
26
|
-
def remove
|
27
|
-
lines = format(commenter.new(old_comments, new_comments).remove) + file_lines_without_comments
|
28
|
-
remove_spacing! lines
|
29
|
-
write { lines.join }
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
attr_reader :file_path, :file_lines, :new_comments, :old_comments, :formatter, :commenter
|
35
|
-
|
36
|
-
def file_comments
|
37
|
-
file_lines.select { |line| line =~ formatter.valid_formats }
|
38
|
-
end
|
39
|
-
|
40
|
-
def file_lines_without_comments
|
41
|
-
file_lines.reject { |line| old_comments.include? line }
|
42
|
-
end
|
43
|
-
|
44
|
-
# :reek:UtilityFunction
|
45
|
-
def format lines
|
46
|
-
lines.map { |line| "#{line}\n" }
|
47
|
-
end
|
48
|
-
|
49
|
-
# :reek:UtilityFunction
|
50
|
-
def insert_spacing! lines, comments
|
51
|
-
comment_count = comments.size
|
52
|
-
|
53
|
-
return if comments.empty?
|
54
|
-
return if lines.size == 1
|
55
|
-
return if lines[comment_count] == "\n"
|
56
|
-
|
57
|
-
lines.insert comment_count, "\n"
|
58
|
-
end
|
59
|
-
|
60
|
-
# :reek:UtilityFunction
|
61
|
-
def remove_spacing! lines
|
62
|
-
lines.delete_at 0 if lines.first == "\n"
|
63
|
-
end
|
64
|
-
|
65
|
-
def write
|
66
|
-
File.open(file_path, "w") { |file| file.write yield }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|