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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f520d4523de27f6ff372f701a852edcd1cd98227c1c86baa5eb3377290be461
4
- data.tar.gz: '08e91032f9bb0515d06da796305caf512f248e8488dd7e71f895cd1cc6e6f0c5'
3
+ metadata.gz: 1d774cddf775dd01454ae0c4e330a26fe1839dbc1425faf320fb48b47c2839e8
4
+ data.tar.gz: c00d6e9b8697af0dbd01aa4431d73e67506b51a0cdffaa9c60162f2758ca17a9
5
5
  SHA512:
6
- metadata.gz: ca422a74af731888d2c06c4b7772e1ce09ccf5e9b1e41c22590796f15faea84ba57d296de218ece4627eeb0f636ff592bee4cfa9c2288c48c353fe8513b519c9
7
- data.tar.gz: 98b0e252098ac3b158e6abdadb982dd43aed0dbb0763b51adea6b1d6b165279e5ffdaa4feab781dad9045e6be69add27bdb5cad45db27d41ee9e08fc7c536dfe
6
+ metadata.gz: 97810ad84783a1bab7b7023af8a21778eb5e1a2fff5e956ecf6fa6dd5372df0afc4a6e649bc556a9808bc12ceabf6d68d9dc0d1297e60323c15a69ceabfdd8bf
7
+ data.tar.gz: 7e1131fddee6223d489df2a8a6eeb02d05269fdf8a584bc74749065619e6b644b699d589895d9fdc7f63f71ef0fc20b944874740d537265a0e90263bc3ef7035
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -150,7 +150,7 @@ additional liability.
150
150
 
151
151
  END OF TERMS AND CONDITIONS
152
152
 
153
- Copyright link:https://www.alchemists.io[Alchemists].
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]
@@ -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 add pragmas to single or multiple Ruby
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 adding a pragma or multiple pragmas to single or multiple source files.
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.html]
40
- image::https://www.alchemists.io/images/screencasts/pragmater/cover-original.png[Screencast,role=focal_point]
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 2.7.x]
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: `+pragmater help+`
61
+ From the command line, type: `pragmater --help`
80
62
 
81
63
  ....
82
- pragmater -a, [--add=PATH] # Add comments to source file(s).
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
- Both the `+--add+` and `+--remove+` commands support options for specifying pragmas and/or included
90
- files (viewable by running `+pragmater --help --add+` or `+pragmater --help --remove+`):
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
- -c, [--comments=one two three] # Define desired comments
94
- -i, [--includes=one two three] # Include specific files and/or directories
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
- Example (same options could be used for the `+--remove+` command too):
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 --add --comments "# frozen_string_literal: true" --includes "Gemfile" "Guardfile" "Rakefile" ".gemspec" "config.ru" "bin/**/*" "**/*.rake" "**/*.rb"
89
+ pragmater --insert --comments "# frozen_string_literal: true" --includes "Gemfile" "Guardfile" "Rakefile" ".gemspec" "config.ru" "bin/**/*" "**/*.rake" "**/*.rb"
102
90
  ----
103
91
 
104
- The `--add` and `--remove` commands default to the current working directory so a path isn’t
105
- necessary unless you want to run Pragmater on a directory structure _other than_ your current
106
- working directory.
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
- :add:
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 this default configuration, modify, and save as your own custom
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
- * `add`: Defines global/local comments and/or file include lists when adding pragmas. The `comments`
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
- Despite Ruby allowing you to do this, it is _not recommended_ to use the above examples as it leads
260
- to hard to read code. Instead use the following:
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
- immutable = "test".freeze
265
- mutable = "test"
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
- While this requires extra typing, it expresses intent more clearly. There is a slight caveat to this
269
- rule in which the use of `+String#-@+` was http://bit.ly/2DGAjgG[enhanced in Ruby 2.5.0] to
270
- _deduplicate_ all instances of the same string thus reducing your memory footprint. This can be
271
- valuable in situations where you are not using the frozen string comment and need to selectively
272
- freeze strings.
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.html[Brooke Kuhlmann].
323
+ Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
@@ -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.start
10
+ Pragmater::CLI::Shell.new.call ARGV
@@ -1,8 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "pragmater/identity"
4
- require "pragmater/formatter"
5
- require "pragmater/commenter"
6
- require "pragmater/writer"
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