pragmater 7.2.0 → 9.0.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: 17f31f5ee7db80b11e49894b0db270e17c1fcdedb97fd9fb19bfebc04af238c2
4
- data.tar.gz: fe4b1203fb590733575f72ccc569481617b978a7949dd13605582fb7a52b7bfe
3
+ metadata.gz: 3510b74dca65adfeed1751708bb5f85b1520cf3d226e7ff1493858431666b32f
4
+ data.tar.gz: 1fcf9908e0de075ae96fc609ffe94209c13dc25676fe3c87b371083601b59451
5
5
  SHA512:
6
- metadata.gz: 5e5f6b2b569226308f251b080d7e51df7352f23dfa33be98afef5424982566d9a8e55f234c052752554ba2e1f8c10740b22859ed39de06a8fd03d096e1dcd15c
7
- data.tar.gz: 5961184d11177ccea0a041783b6df77e4cced27a5088c63325915ed75fc20748e2ea0c59a05d0071d4d8786154905e83fda922788a67c6386b6241d4025e7177
6
+ metadata.gz: 783e0fe7bc7d0c6a2993e2a77f3b4093bd1f9b1e1b272ac014a39805487cb36b8cd8f30958461d5de19f12529b23f10bce188ebb0ed104d95c1d291097192c65
7
+ data.tar.gz: 40ce62fd3b9a050a951c91c423cb2787f82ffd0de568eaa17ff2e9efcd6351bb4edd860bdaac15c019a6122115ce1e174908a46c87fdc407d0953a82cd1e76cd
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.
@@ -45,8 +47,6 @@ image::https://www.alchemists.io/images/screencasts/pragmater/cover.svg[Screenca
45
47
 
46
48
  == Setup
47
49
 
48
- === Production
49
-
50
50
  To install, run:
51
51
 
52
52
  [source,bash]
@@ -54,55 +54,43 @@ 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 working
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
106
94
  directory.
107
95
 
108
96
  === Customization
@@ -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:
@@ -128,10 +116,10 @@ Feel free to take the above configuration, modify, and save as your own custom `
128
116
 
129
117
  The `configuration.yml` file can be configured as follows:
130
118
 
131
- * `add`: Defines global/local comments and/or file include lists when adding pragmas. The `comments`
132
- 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.
133
121
  * `remove`: Defines global/local comments and/or file include lists when removing pragmas. The
134
- `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.
135
123
 
136
124
  === Available Pragmas
137
125
 
@@ -255,17 +243,7 @@ immutable = -"test"
255
243
  mutable = +"test"
256
244
  ----
257
245
 
258
- Despite Ruby allowing you to do this, it is _not recommended_ to use the above examples as it leads
259
- to hard to read code. Instead use the following:
260
-
261
- [source,ruby]
262
- ----
263
- immutable = "test".freeze
264
- mutable = "test"
265
- ----
266
-
267
- While this requires extra typing, it expresses intent more clearly. There is a slight caveat to this
268
- rule in which the use of `+String#-@+` was http://bit.ly/2DGAjgG[enhanced in Ruby 2.5.0] to
246
+ 💡 The use of `+String#-@+`, specifically, was http://bit.ly/2DGAjgG[enhanced in Ruby 2.5.0] to
269
247
  _deduplicate_ all instances of the same string thus reducing your memory footprint. This can be
270
248
  valuable in situations where you are not using the frozen string comment and need to selectively
271
249
  freeze strings.
@@ -288,6 +266,24 @@ presented together for a visual comparison:
288
266
  One oddity to the above is the use of `# !/usr/bin/env ruby` is not allowed but `#! /usr/bin/env
289
267
  ruby` is which is why spacing is slightly different for shell pragmas.
290
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
+ ----
286
+
291
287
  == Tests
292
288
 
293
289
  To test, run:
@@ -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
@@ -0,0 +1,6 @@
1
+ :insert:
2
+ :comments: []
3
+ :includes: []
4
+ :remove:
5
+ :comments: []
6
+ :includes: []
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module CLI
5
+ module Options
6
+ # Defines gem insert and remove options.
7
+ class InsertRemove
8
+ def initialize values, parser: OptionParser.new
9
+ @values = values
10
+ @parser = parser
11
+ end
12
+
13
+ def call
14
+ parser.separator "\nOPTIONS:\n"
15
+ parser.separator "\nInsert/Remove:\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_comments
25
+ parser.on "--comments a,b,c", Array, "Add pragma comments." do |comments|
26
+ values[:comments] = comments
27
+ end
28
+ end
29
+
30
+ def add_includes
31
+ parser.on "--includes a,b,c", Array, "Add console support." do |includes|
32
+ values[:includes] = includes
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end