pragmater 7.0.0 → 8.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module Formatters
5
+ # Formats shebang pragmas in a consistent manner.
6
+ class Shebang
7
+ PATTERN = %r(\A\#!\s?/.*ruby\Z).freeze
8
+
9
+ def initialize string, pattern: PATTERN
10
+ @string = string
11
+ @pattern = pattern
12
+ end
13
+
14
+ def call
15
+ return string unless string.match? pattern
16
+
17
+ string.split("!").then { |octothorpe, path| "#{octothorpe}! #{path.strip}" }
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :string, :pattern
23
+ end
24
+ end
25
+ end
@@ -3,20 +3,10 @@
3
3
  module Pragmater
4
4
  # Gem identity information.
5
5
  module Identity
6
- def self.name
7
- "pragmater"
8
- end
9
-
10
- def self.label
11
- "Pragmater"
12
- end
13
-
14
- def self.version
15
- "7.0.0"
16
- end
17
-
18
- def self.version_label
19
- "#{label} #{version}"
20
- end
6
+ NAME = "pragmater"
7
+ LABEL = "Pragmater"
8
+ VERSION = "8.1.0"
9
+ VERSION_LABEL = "#{LABEL} #{VERSION}"
10
+ SUMMARY = "A command line interface for managing/formatting source file pragma comments."
21
11
  end
22
12
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module Parsers
5
+ # Manages pragma comments.
6
+ class Comments
7
+ def initialize older, newer, formatter: Formatters::Main
8
+ @formatter = formatter
9
+ @older = format older
10
+ @newer = format newer
11
+ end
12
+
13
+ def insert
14
+ older.union newer
15
+ end
16
+
17
+ def remove
18
+ older - older.intersection(newer)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :formatter, :older, :newer
24
+
25
+ def format pragmas
26
+ Array(pragmas).map { |pragma| formatter.new(pragma).call }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module Parsers
5
+ # Parses a file into pragma comment and body lines.
6
+ class File
7
+ def initialize pattern: Formatters::Main::PATTERN,
8
+ comments: Comments,
9
+ processor: Processors::Handler.new
10
+ @pattern = pattern
11
+ @comments = comments
12
+ @processor = processor
13
+ end
14
+
15
+ def call path, new_comments, action:
16
+ path.each_line
17
+ .partition { |line| line.match? pattern }
18
+ .then do |old_comments, body|
19
+ processor.call action, wrap_in_new_line(old_comments, new_comments, action), body
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :pattern, :comments, :processor
26
+
27
+ def wrap_in_new_line old_comments, new_comments, action
28
+ comments.new(old_comments, new_comments).public_send(action).map { |line| "#{line}\n" }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module Processors
5
+ # Handles the insertion or removal of pragma comments.
6
+ class Handler
7
+ DEFAULTS = {
8
+ insert: Inserter,
9
+ remove: Remover
10
+ }.freeze
11
+
12
+ def initialize processors: DEFAULTS
13
+ @processors = processors
14
+ end
15
+
16
+ def call action, comments, body
17
+ processors.fetch(action).new(comments, body).call
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :processors
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module Processors
5
+ # Inserts new pragma comments.
6
+ class Inserter
7
+ def initialize comments, body
8
+ @comments = comments
9
+ @body = body
10
+ end
11
+
12
+ def call
13
+ body.first.then do |first|
14
+ comments.append "\n" unless first == "\n" || body.empty?
15
+ comments + body
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :comments, :body
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module Processors
5
+ # Removes existing pragma comments.
6
+ class Remover
7
+ def initialize comments, body
8
+ @comments = comments
9
+ @body = body
10
+ end
11
+
12
+ def call
13
+ body.first.then do |first_line|
14
+ body.delete_at 0 if first_line == "\n" && comments.empty?
15
+ comments + body
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :comments, :body
22
+ end
23
+ end
24
+ end
@@ -1,32 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "refinements/pathnames"
4
+
3
5
  module Pragmater
4
6
  # Adds/removes pragma comments for files in given path.
5
7
  class Runner
6
- # rubocop:disable Metrics/ParameterLists
7
- def initialize path = ".", comments: [], includes: [], writer: Writer
8
- @path = Pathname path
9
- @comments = Array comments
10
- @includes = Array includes
11
- @writer = writer
12
- end
13
- # rubocop:enable Metrics/ParameterLists
8
+ using Refinements::Pathnames
14
9
 
15
- def files
16
- return [] unless path.exist? && path.directory? && !includes.empty?
10
+ def self.for **attributes
11
+ new Context[attributes]
12
+ end
17
13
 
18
- Pathname.glob(%(#{path}/{#{includes.join ","}})).select(&:file?)
14
+ def initialize context, parser: Parsers::File.new
15
+ @context = context
16
+ @parser = parser
19
17
  end
20
18
 
21
- def run action:
22
- files.each do |file|
23
- writer.new(file, comments).public_send action
24
- yield file if block_given?
25
- end
19
+ def call
20
+ Pathname(context.root_dir).files("{#{context.includes.join ","}}").map(&method(:write))
26
21
  end
27
22
 
28
23
  private
29
24
 
30
- attr_reader :path, :comments, :includes, :writer
25
+ attr_reader :context, :parser
26
+
27
+ def write path
28
+ path.tap do |a_path|
29
+ a_path.write parser.call(a_path, context.comments, action: context.action).join
30
+ end
31
+ end
31
32
  end
32
33
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragmater
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIC/jCCAeagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAlMSMwIQY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MOO3CdPMtSk
27
- OrWpbzCL+nbbXqeoqiHgZaUvcyyQrGj5sQRxMTzuMXzzQxtHnuTuKrcz16HMTX/O
28
- dKvURM+1PwDCzC5tvRwjhUJIizau6+MtkFCvJHmaAj1aZL3odcPejHj5Hxt/0CUW
29
- y84=
23
+ 2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAIHhAlD3po4sTYqacXaQ
24
+ XI9jIhrfMy//2PgbHWcETtlJPBeNUbbSNBABcllUHKqYsVDlSvSmss034KSWNR8F
25
+ bF1GcloicyvcCC4y6IoW4it0COAcdeaaxkxiBSgKdQFpff9REnDlIKK4uQ9lLxIo
26
+ Y2G5xubiziKZkyfWFuSr67PIjW3Bu673D1JVBArhA1qbgQmYQcy1CkGOjo+iO8Nf
27
+ 7u/QSfBHb+r/bXhKscDgPpnKwbUmvgO2+94zJG9KsrmIydlzYfsD09aXKx0t6Xy4
28
+ 2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
+ QWc=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-01-01 00:00:00.000000000 Z
31
+ date: 2020-11-14 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
- name: runcom
34
+ name: refinements
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '6.0'
39
+ version: '7.14'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '6.0'
46
+ version: '7.14'
47
47
  - !ruby/object:Gem::Dependency
48
- name: thor
48
+ name: runcom
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.20'
53
+ version: '6.4'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.20'
60
+ version: '6.4'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler-audit
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.6'
67
+ version: '0.7'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0.6'
74
+ version: '0.7'
75
75
  - !ruby/object:Gem::Dependency
76
- name: climate_control
76
+ name: bundler-leak
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
@@ -106,28 +106,28 @@ dependencies:
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0.12'
109
+ version: '0.13'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '0.12'
116
+ version: '0.13'
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: pry-byebug
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '3.7'
123
+ version: '3.9'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '3.7'
130
+ version: '3.9'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: rake
133
133
  requirement: !ruby/object:Gem::Requirement
@@ -148,56 +148,56 @@ dependencies:
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '5.4'
151
+ version: '6.0'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '5.4'
158
+ version: '6.0'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: rspec
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '3.9'
165
+ version: '3.10'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '3.9'
172
+ version: '3.10'
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: rubocop
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: '0.78'
179
+ version: '1.3'
180
180
  type: :development
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: '0.78'
186
+ version: '1.3'
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: rubocop-performance
189
189
  requirement: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - "~>"
192
192
  - !ruby/object:Gem::Version
193
- version: '1.5'
193
+ version: '1.8'
194
194
  type: :development
195
195
  prerelease: false
196
196
  version_requirements: !ruby/object:Gem::Requirement
197
197
  requirements:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
- version: '1.5'
200
+ version: '1.8'
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: rubocop-rake
203
203
  requirement: !ruby/object:Gem::Requirement
@@ -218,56 +218,70 @@ dependencies:
218
218
  requirements:
219
219
  - - "~>"
220
220
  - !ruby/object:Gem::Version
221
- version: '1.37'
221
+ version: '2.0'
222
222
  type: :development
223
223
  prerelease: false
224
224
  version_requirements: !ruby/object:Gem::Requirement
225
225
  requirements:
226
226
  - - "~>"
227
227
  - !ruby/object:Gem::Version
228
- version: '1.37'
228
+ version: '2.0'
229
229
  - !ruby/object:Gem::Dependency
230
230
  name: simplecov
231
231
  requirement: !ruby/object:Gem::Requirement
232
232
  requirements:
233
233
  - - "~>"
234
234
  - !ruby/object:Gem::Version
235
- version: '0.17'
235
+ version: '0.19'
236
236
  type: :development
237
237
  prerelease: false
238
238
  version_requirements: !ruby/object:Gem::Requirement
239
239
  requirements:
240
240
  - - "~>"
241
241
  - !ruby/object:Gem::Version
242
- version: '0.17'
243
- description:
242
+ version: '0.19'
243
+ description:
244
244
  email:
245
245
  - brooke@alchemists.io
246
246
  executables:
247
247
  - pragmater
248
248
  extensions: []
249
249
  extra_rdoc_files:
250
- - README.md
251
- - LICENSE.md
250
+ - README.adoc
251
+ - LICENSE.adoc
252
252
  files:
253
- - LICENSE.md
254
- - README.md
253
+ - LICENSE.adoc
254
+ - README.adoc
255
255
  - bin/pragmater
256
256
  - lib/pragmater.rb
257
- - lib/pragmater/cli.rb
258
- - lib/pragmater/commenter.rb
259
- - lib/pragmater/formatter.rb
257
+ - lib/pragmater/cli/helper.rb
258
+ - lib/pragmater/cli/options/assembler.rb
259
+ - lib/pragmater/cli/options/configuration.rb
260
+ - lib/pragmater/cli/options/core.rb
261
+ - lib/pragmater/cli/options/defaults.yml
262
+ - lib/pragmater/cli/options/insert_remove.rb
263
+ - lib/pragmater/cli/options/merger.rb
264
+ - lib/pragmater/cli/shell.rb
265
+ - lib/pragmater/context.rb
266
+ - lib/pragmater/formatters/general.rb
267
+ - lib/pragmater/formatters/main.rb
268
+ - lib/pragmater/formatters/shebang.rb
260
269
  - lib/pragmater/identity.rb
270
+ - lib/pragmater/parsers/comments.rb
271
+ - lib/pragmater/parsers/file.rb
272
+ - lib/pragmater/processors/handler.rb
273
+ - lib/pragmater/processors/inserter.rb
274
+ - lib/pragmater/processors/remover.rb
261
275
  - lib/pragmater/runner.rb
262
- - lib/pragmater/writer.rb
263
- homepage: https://github.com/bkuhlmann/pragmater
276
+ homepage: https://www.alchemists.io/projects/pragmater
264
277
  licenses:
265
278
  - Apache-2.0
266
279
  metadata:
267
- source_code_uri: https://github.com/bkuhlmann/pragmater
268
- changelog_uri: https://github.com/bkuhlmann/pragmater/blob/master/CHANGES.md
269
280
  bug_tracker_uri: https://github.com/bkuhlmann/pragmater/issues
270
- post_install_message:
281
+ changelog_uri: https://www.alchemists.io/projects/pragmater/changes.html
282
+ documentation_uri: https://www.alchemists.io/projects/pragmater
283
+ source_code_uri: https://github.com/bkuhlmann/pragmater
284
+ post_install_message:
271
285
  rdoc_options: []
272
286
  require_paths:
273
287
  - lib
@@ -282,8 +296,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
296
  - !ruby/object:Gem::Version
283
297
  version: '0'
284
298
  requirements: []
285
- rubygems_version: 3.1.2
286
- signing_key:
299
+ rubygems_version: 3.1.4
300
+ signing_key:
287
301
  specification_version: 4
288
302
  summary: A command line interface for managing/formatting source file pragma comments.
289
303
  test_files: []