pragmater 7.1.0 → 8.3.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.adoc +1 -1
- data/README.adoc +72 -59
- data/bin/pragmater +4 -3
- 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 +2 -1
- 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 +30 -227
- metadata.gz.sig +0 -0
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d774cddf775dd01454ae0c4e330a26fe1839dbc1425faf320fb48b47c2839e8
|
4
|
+
data.tar.gz: c00d6e9b8697af0dbd01aa4431d73e67506b51a0cdffaa9c60162f2758ca17a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97810ad84783a1bab7b7023af8a21778eb5e1a2fff5e956ecf6fa6dd5372df0afc4a6e649bc556a9808bc12ceabf6d68d9dc0d1297e60323c15a69ceabfdd8bf
|
7
|
+
data.tar.gz: 7e1131fddee6223d489df2a8a6eeb02d05269fdf8a584bc74749065619e6b644b699d589895d9fdc7f63f71ef0fc20b944874740d537265a0e90263bc3ef7035
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/LICENSE.adoc
CHANGED
@@ -150,7 +150,7 @@ additional liability.
|
|
150
150
|
|
151
151
|
END OF TERMS AND CONDITIONS
|
152
152
|
|
153
|
-
Copyright link:https://www.alchemists.io[
|
153
|
+
Copyright 2015 link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
154
154
|
|
155
155
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
156
156
|
compliance with the License. You may obtain a link:https://www.apache.org/licenses/LICENSE-2.0[copy]
|
data/README.adoc
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
[link=http://badge.fury.io/rb/pragmater]
|
8
8
|
image::https://badge.fury.io/rb/pragmater.svg[Gem Version]
|
9
|
+
[link=https://www.alchemists.io/projects/code_quality]
|
10
|
+
image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchemists Style Guide]
|
9
11
|
[link=https://circleci.com/gh/bkuhlmann/pragmater]
|
10
12
|
image::https://circleci.com/gh/bkuhlmann/pragmater.svg?style=svg[Circle CI Status]
|
11
13
|
|
@@ -21,14 +23,14 @@ Examples:
|
|
21
23
|
----
|
22
24
|
|
23
25
|
With https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released[Ruby 2.3.0], frozen strings
|
24
|
-
are supported via a pragma. This gem provides an easy way to
|
25
|
-
source files in order to benefit from improved memory and concurrency performance.
|
26
|
+
are supported via a pragma. This gem provides an easy way to insert or remove pragmas to single or
|
27
|
+
multiple Ruby source files in order to benefit from improved memory and concurrency performance.
|
26
28
|
|
27
29
|
toc::[]
|
28
30
|
|
29
31
|
== Features
|
30
32
|
|
31
|
-
* Supports
|
33
|
+
* Supports inserting a pragma or multiple pragmas to single or multiple source files.
|
32
34
|
* Supports removing pragma(s) from single or multiple source files.
|
33
35
|
* Supports file list filtering. Defaults to any file.
|
34
36
|
* Ensures duplicate pragmas never exist.
|
@@ -36,17 +38,15 @@ toc::[]
|
|
36
38
|
|
37
39
|
== Screencasts
|
38
40
|
|
39
|
-
[link=https://www.alchemists.io/screencasts/pragmater
|
40
|
-
image::https://www.alchemists.io/images/screencasts/pragmater/cover
|
41
|
+
[link=https://www.alchemists.io/screencasts/pragmater]
|
42
|
+
image::https://www.alchemists.io/images/screencasts/pragmater/cover.svg[Screencast,600,240,role=focal_point]
|
41
43
|
|
42
44
|
== Requirements
|
43
45
|
|
44
|
-
. https://www.ruby-lang.org[Ruby
|
46
|
+
. https://www.ruby-lang.org[Ruby]
|
45
47
|
|
46
48
|
== Setup
|
47
49
|
|
48
|
-
=== Production
|
49
|
-
|
50
50
|
To install, run:
|
51
51
|
|
52
52
|
[source,bash]
|
@@ -54,56 +54,44 @@ To install, run:
|
|
54
54
|
gem install pragmater
|
55
55
|
----
|
56
56
|
|
57
|
-
=== Development
|
58
|
-
|
59
|
-
To contribute, run:
|
60
|
-
|
61
|
-
[source,bash]
|
62
|
-
----
|
63
|
-
git clone https://github.com/bkuhlmann/pragmater.git
|
64
|
-
cd pragmater
|
65
|
-
bin/setup
|
66
|
-
----
|
67
|
-
|
68
|
-
You can also use the IRB console for direct access to all objects:
|
69
|
-
|
70
|
-
[source,bash]
|
71
|
-
----
|
72
|
-
bin/console
|
73
|
-
----
|
74
|
-
|
75
57
|
== Usage
|
76
58
|
|
77
59
|
=== Command Line Interface (CLI)
|
78
60
|
|
79
|
-
From the command line, type:
|
61
|
+
From the command line, type: `pragmater --help`
|
80
62
|
|
81
63
|
....
|
82
|
-
|
83
|
-
pragmater -c, [--config] # Manage gem configuration.
|
84
|
-
pragmater -h, [--help=COMMAND] # Show this message or get help for a command.
|
85
|
-
pragmater -r, [--remove=PATH] # Remove comments from source file(s).
|
86
|
-
pragmater -v, [--version] # Show gem version.
|
87
|
-
....
|
64
|
+
Pragmater - A command line interface for managing/formatting source file pragma comments.
|
88
65
|
|
89
|
-
|
90
|
-
|
66
|
+
USAGE:
|
67
|
+
-v, --version Show gem version.
|
68
|
+
-h, --help Show this message.
|
69
|
+
-c, --config [options] Manage gem configuration.
|
70
|
+
-i, --insert [PATH] Insert pragam comments into files.
|
71
|
+
-r, --remove [options] Remove pragam comments from files.
|
91
72
|
|
92
|
-
|
93
|
-
|
94
|
-
|
73
|
+
OPTIONS:
|
74
|
+
|
75
|
+
Insert/Remove:
|
76
|
+
--comments a,b,c Add pragma comments.
|
77
|
+
--includes a,b,c Add console support.
|
78
|
+
|
79
|
+
Configuration:
|
80
|
+
--edit Edit configuration.
|
81
|
+
--info Print configuration.
|
95
82
|
....
|
96
83
|
|
97
|
-
|
84
|
+
Both the `--insert` and `--remove` commands support the same options for specifying pragmas and/or
|
85
|
+
included files. Example:
|
98
86
|
|
99
87
|
[source,bash]
|
100
88
|
----
|
101
|
-
pragmater --
|
89
|
+
pragmater --insert --comments "# frozen_string_literal: true" --includes "Gemfile" "Guardfile" "Rakefile" ".gemspec" "config.ru" "bin/**/*" "**/*.rake" "**/*.rb"
|
102
90
|
----
|
103
91
|
|
104
|
-
The `--
|
105
|
-
necessary unless you want to run Pragmater
|
106
|
-
|
92
|
+
The `--insert` and `--remove` commands default to the current working directory so a path isn’t
|
93
|
+
necessary unless you want to run Pragmater in a directory structure other than your current working
|
94
|
+
directory.
|
107
95
|
|
108
96
|
=== Customization
|
109
97
|
|
@@ -116,7 +104,7 @@ The default configuration is as follows:
|
|
116
104
|
|
117
105
|
[source,yaml]
|
118
106
|
----
|
119
|
-
:
|
107
|
+
:insert:
|
120
108
|
:comments: []
|
121
109
|
:includes: []
|
122
110
|
:remove:
|
@@ -124,15 +112,14 @@ The default configuration is as follows:
|
|
124
112
|
:includes: []
|
125
113
|
----
|
126
114
|
|
127
|
-
Feel free to take
|
128
|
-
`configuration.yml`.
|
115
|
+
Feel free to take the above configuration, modify, and save as your own custom `configuration.yml`.
|
129
116
|
|
130
117
|
The `configuration.yml` file can be configured as follows:
|
131
118
|
|
132
|
-
* `
|
133
|
-
and `includes` options can be either a single string or an array.
|
119
|
+
* `insert`: Defines global/local comments and/or file include lists when inserting pragmas. The
|
120
|
+
`comments` and `includes` options can be either a single string or an array of strings.
|
134
121
|
* `remove`: Defines global/local comments and/or file include lists when removing pragmas. The
|
135
|
-
`comments` and `includes` options can be either a single string or an array.
|
122
|
+
`comments` and `includes` options can be either a single string or an array of strings.
|
136
123
|
|
137
124
|
=== Available Pragmas
|
138
125
|
|
@@ -256,20 +243,46 @@ immutable = -"test"
|
|
256
243
|
mutable = +"test"
|
257
244
|
----
|
258
245
|
|
259
|
-
|
260
|
-
|
246
|
+
💡 The use of `+String#-@+`, specifically, was http://bit.ly/2DGAjgG[enhanced in Ruby 2.5.0] to
|
247
|
+
_deduplicate_ all instances of the same string thus reducing your memory footprint. This can be
|
248
|
+
valuable in situations where you are not using the frozen string comment and need to selectively
|
249
|
+
freeze strings.
|
250
|
+
|
251
|
+
=== Consistency
|
252
|
+
|
253
|
+
As an added bonus, this gem ensures pragmas for all analyzed files are formatted in a consistent
|
254
|
+
style. This means there is always a space after the octothorpe (`#`). Here are multiple pragmas
|
255
|
+
presented together for a visual comparison:
|
261
256
|
|
262
257
|
[source,ruby]
|
263
258
|
----
|
264
|
-
|
265
|
-
|
259
|
+
#! /usr/bin/env ruby
|
260
|
+
# encoding: UTF-8
|
261
|
+
# coding: UTF-8
|
262
|
+
# frozen_string_literal: true
|
263
|
+
# warn_indent: true
|
266
264
|
----
|
267
265
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
266
|
+
One oddity to the above is the use of `# !/usr/bin/env ruby` is not allowed but `#! /usr/bin/env
|
267
|
+
ruby` is which is why spacing is slightly different for shell pragmas.
|
268
|
+
|
269
|
+
== Development
|
270
|
+
|
271
|
+
To contribute, run:
|
272
|
+
|
273
|
+
[source,bash]
|
274
|
+
----
|
275
|
+
git clone https://github.com/bkuhlmann/pragmater.git
|
276
|
+
cd pragmater
|
277
|
+
bin/setup
|
278
|
+
----
|
279
|
+
|
280
|
+
You can also use the IRB console for direct access to all objects:
|
281
|
+
|
282
|
+
[source,bash]
|
283
|
+
----
|
284
|
+
bin/console
|
285
|
+
----
|
273
286
|
|
274
287
|
== Tests
|
275
288
|
|
@@ -307,4 +320,4 @@ Read link:CHANGES.adoc[CHANGES] for details.
|
|
307
320
|
|
308
321
|
== Credits
|
309
322
|
|
310
|
-
Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann
|
323
|
+
Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
data/bin/pragmater
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
# TODO: Remove once the Pattern Matching feature is fully supported.
|
5
|
+
Warning[:experimental] = false
|
6
|
+
|
4
7
|
require "pragmater"
|
5
|
-
require "pragmater/cli"
|
6
|
-
require "pragmater/identity"
|
7
8
|
|
8
9
|
Process.setproctitle Pragmater::Identity::VERSION_LABEL
|
9
|
-
Pragmater::CLI.
|
10
|
+
Pragmater::CLI::Shell.new.call ARGV
|
data/lib/pragmater.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "pragmater/identity"
|
4
|
-
require "pragmater/
|
5
|
-
require "pragmater/
|
6
|
-
require "pragmater/
|
4
|
+
require "pragmater/formatters/general"
|
5
|
+
require "pragmater/formatters/shebang"
|
6
|
+
require "pragmater/formatters/main"
|
7
|
+
require "pragmater/parsers/comments"
|
8
|
+
require "pragmater/parsers/file"
|
9
|
+
require "pragmater/processors/inserter"
|
10
|
+
require "pragmater/processors/remover"
|
11
|
+
require "pragmater/processors/handler"
|
12
|
+
require "pragmater/context"
|
7
13
|
require "pragmater/runner"
|
8
|
-
require "pragmater/cli"
|
14
|
+
require "pragmater/cli/options/configuration"
|
15
|
+
require "pragmater/cli/options/insert_remove"
|
16
|
+
require "pragmater/cli/options/core"
|
17
|
+
require "pragmater/cli/options/assembler"
|
18
|
+
require "pragmater/cli/options/merger"
|
19
|
+
require "pragmater/cli/helper"
|
20
|
+
require "pragmater/cli/shell"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require "open3"
|
5
|
+
require "logger"
|
6
|
+
|
7
|
+
module Pragmater
|
8
|
+
module CLI
|
9
|
+
# A simple delegator for common shell functionality.
|
10
|
+
class Helper
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
LOGGER = Logger.new STDOUT,
|
14
|
+
formatter: (
|
15
|
+
proc do |_severity, _datetime, _program_name, message|
|
16
|
+
"#{message}\n"
|
17
|
+
end
|
18
|
+
)
|
19
|
+
|
20
|
+
delegate %i[info error fatal debug unknown] => :logger
|
21
|
+
|
22
|
+
def initialize commander: Open3, logger: LOGGER
|
23
|
+
@commander = commander
|
24
|
+
@logger = logger
|
25
|
+
end
|
26
|
+
|
27
|
+
def run command
|
28
|
+
commander.capture3 command
|
29
|
+
end
|
30
|
+
|
31
|
+
def warn message
|
32
|
+
logger.warn message
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :commander, :logger
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "forwardable"
|
5
|
+
|
6
|
+
module Pragmater
|
7
|
+
module CLI
|
8
|
+
module Options
|
9
|
+
# Coalesces all options and arguments into a single hash for further processing.
|
10
|
+
class Assembler
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
PARSER = OptionParser.new nil, 40, " "
|
14
|
+
SECTIONS = [Core, InsertRemove, Configuration].freeze
|
15
|
+
|
16
|
+
EXCEPTIONS = [
|
17
|
+
OptionParser::InvalidOption,
|
18
|
+
OptionParser::MissingArgument,
|
19
|
+
OptionParser::InvalidArgument
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
delegate %i[to_s] => :parser
|
23
|
+
|
24
|
+
def initialize sections: SECTIONS, parser: PARSER, exceptions: EXCEPTIONS
|
25
|
+
@sections = sections
|
26
|
+
@parser = parser
|
27
|
+
@options = {}
|
28
|
+
@exceptions = exceptions
|
29
|
+
end
|
30
|
+
|
31
|
+
def call arguments = []
|
32
|
+
sections.each { |section| section.new(options, parser: parser).call }
|
33
|
+
parser.parse! arguments
|
34
|
+
options
|
35
|
+
rescue *EXCEPTIONS
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :parser, :sections, :options, :exceptions
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pragmater
|
4
|
+
module CLI
|
5
|
+
module Options
|
6
|
+
# Defines gem configuration options.
|
7
|
+
class Configuration
|
8
|
+
def initialize values, parser: OptionParser.new
|
9
|
+
@parser = parser
|
10
|
+
@values = values
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
parser.separator "\nConfiguration:\n"
|
15
|
+
private_methods.grep(/add_/).each { |method| __send__ method }
|
16
|
+
parser
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :parser, :values
|
22
|
+
|
23
|
+
def add_edit
|
24
|
+
parser.on "--edit", "Edit configuration." do
|
25
|
+
values[:edit] = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_info
|
30
|
+
parser.on "--info", "Print configuration." do
|
31
|
+
values[:info] = true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pragmater
|
4
|
+
module CLI
|
5
|
+
module Options
|
6
|
+
# Defines gem primary options.
|
7
|
+
class Core
|
8
|
+
def initialize values, parser: OptionParser.new
|
9
|
+
@values = values
|
10
|
+
@parser = parser
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
parser.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
|
15
|
+
parser.separator "\nUSAGE:\n"
|
16
|
+
private_methods.grep(/add_/).each { |method| __send__ method }
|
17
|
+
parser
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :values, :parser
|
23
|
+
|
24
|
+
def add_configuration
|
25
|
+
parser.on "-c", "--config [options]", "Manage gem configuration." do
|
26
|
+
values[:config] = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_insert
|
31
|
+
parser.on "-i", "--insert [PATH]", "Insert pragam comments into files." do |path|
|
32
|
+
values[:insert] = path || "."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_remove
|
37
|
+
parser.on "-r", "--remove [options]", "Remove pragam comments from files." do |path|
|
38
|
+
values[:remove] = path || "."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_version
|
43
|
+
parser.on "-v", "--version", "Show gem version." do
|
44
|
+
values[:version] = Identity::VERSION
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_help
|
49
|
+
parser.on "-h", "--help", "Show this message." do
|
50
|
+
values[:help] = true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|