pragmater 3.1.0 → 4.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
  SHA1:
3
- metadata.gz: 62c44182adee2b8134834df3d99e82d38d23050f
4
- data.tar.gz: c48a368afcbe24dc37cc856e6b592142c34de8e6
3
+ metadata.gz: 96c9a16d8a432e8001bf05e2fadba1b2bde5caee
4
+ data.tar.gz: 262b53eb16d75ce63efe509ab4266b9877c5ba57
5
5
  SHA512:
6
- metadata.gz: 5d76f35dde56bd129ae3b77d02298ed4aa62f7fee367f5b0def0646c5ed46a23e2bfc21e17d4b835f2c8d37206d09f9eb96d1dc9a9a46904b978a8624e07179a
7
- data.tar.gz: ec4e072e9334c86f0cf7aa5784a4f7c4c667f5926e955d9f30911bcf4e4b3f147022c1c6d417a040fa1b3ce35d8e20543dcdb2fc121103af60f6dd195ff90b2e
6
+ metadata.gz: d9327285f4442217347e21d59a22bcb27100b5241280c3786a28d05a9798f788cfe5fa1d91cb7e5d4e730206944e5e8249320406c8fe07c7ecef5322664c3100
7
+ data.tar.gz: 8e8a51a1a209e9bba75121cbb2154e0eba4f28fb27f47728a94081697dbc28e65a6a45f588e2f6890ae4594691d9773b8829e5db16435f2b2d93de9cc340ebb2
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Code Climate GPA](https://codeclimate.com/github/bkuhlmann/pragmater.svg)](https://codeclimate.com/github/bkuhlmann/pragmater)
5
5
  [![Code Climate Coverage](https://codeclimate.com/github/bkuhlmann/pragmater/coverage.svg)](https://codeclimate.com/github/bkuhlmann/pragmater)
6
6
  [![Gemnasium Status](https://gemnasium.com/bkuhlmann/pragmater.svg)](https://gemnasium.com/bkuhlmann/pragmater)
7
- [![Travis CI Status](https://secure.travis-ci.org/bkuhlmann/pragmater.svg)](https://travis-ci.org/bkuhlmann/pragmater)
7
+ [![Circle CI Status](https://circleci.com/gh/bkuhlmann/pragmater.svg?style=svg)](https://circleci.com/gh/bkuhlmann/pragmater)
8
8
  [![Patreon](https://img.shields.io/badge/patreon-donate-brightgreen.svg)](https://www.patreon.com/bkuhlmann)
9
9
 
10
10
  A command line interface for managing/formatting source file
@@ -89,29 +89,18 @@ Both the `--add` and `--remove` commands support options for specifying pragma c
89
89
  whitelisted files (viewable by running `pragmater --help --add` or `pragmater --help --remove`):
90
90
 
91
91
  -c, [--comments=one two three] # Pragma comments
92
- -w, [--whitelist=one two three] # File extension whitelist
92
+ -w, [--whitelist=one two three] # File whitelist
93
93
 
94
94
  ## Customization
95
95
 
96
- Should the default settings not be desired, customization is allowed via the `.pragmaterrc` file.
97
- The `.pragmaterrc` can be created at a global and/or local level. Example:
96
+ This gem can be configured via a global configuration:
98
97
 
99
- - Global: `~/.pragmaterrc`
100
- - Local: `<project repository root>/.pragmaterrc`
98
+ ~/.config/pragmater/configuration.yml
101
99
 
102
- Order of precedence for any setting is resolved as follows (with the last taking top priority):
100
+ It can also be configured via [XDG environment variables](https://github.com/bkuhlmann/runcom#xdg)
101
+ as provided by the [Runcom](https://github.com/bkuhlmann/runcom) gem.
103
102
 
104
- 0. Global `~/.pragmaterrc`.
105
- 0. Local project repository `.pragmaterrc`.
106
- 0. CLI option (i.e. `--add` or `--remove` command options).
107
-
108
- Any setting provided to the CLI during runtime would trump a local/global setting and a local
109
- setting would trump a global setting. The global setting is the weakest of all but great for
110
- situations where custom settings should be applied to *all* projects. It is important to note that
111
- local settings completely trump any global settings -- there is no inheritance when local *and*
112
- global settings exist at the same time.
113
-
114
- The `.pragmaterrc` uses the following default settings:
103
+ The default configuration is as follows:
115
104
 
116
105
  :add:
117
106
  :comments: []
@@ -120,7 +109,10 @@ The `.pragmaterrc` uses the following default settings:
120
109
  :comments: []
121
110
  :whitelist: []
122
111
 
123
- Each `.pragmaterrc` setting can be configured as follows:
112
+ Feel free to take this default configuration, modify, and save as your own custom
113
+ `configuration.yml`.
114
+
115
+ The `configuration.yml` file can be configured as follows:
124
116
 
125
117
  - `add`: Defines global/local comments and/or whitelists when adding pragma comments. The `comments`
126
118
  and `whitelist` options can be either a single string or an array of values.
data/lib/pragmater/cli.rb CHANGED
@@ -8,7 +8,6 @@ require "runcom"
8
8
 
9
9
  module Pragmater
10
10
  # The Command Line Interface (CLI) for the gem.
11
- # rubocop:disable Metrics/ClassLength
12
11
  class CLI < Thor
13
12
  include Thor::Actions
14
13
  include ThorPlus::Actions
@@ -16,7 +15,7 @@ module Pragmater
16
15
  package_name Identity.version_label
17
16
 
18
17
  def self.configuration
19
- Runcom::Configuration.new file_name: Identity.file_name, defaults: {
18
+ Runcom::Configuration.new project_name: Identity.name, defaults: {
20
19
  add: {
21
20
  comments: "",
22
21
  whitelist: []
@@ -41,16 +40,20 @@ module Pragmater
41
40
  default: []
42
41
  method_option :whitelist,
43
42
  aliases: "-w",
44
- desc: "File extension whitelist",
43
+ desc: "File whitelist",
45
44
  type: :array,
46
45
  default: []
47
- def add path
46
+ def add path = "."
48
47
  settings = self.class.configuration.merge add: {
49
48
  comments: options[:comments],
50
49
  whitelist: options[:whitelist]
51
50
  }
52
51
 
53
- write path, settings, :add
52
+ runner = Runner.new path,
53
+ comments: settings.dig(:add, :comments),
54
+ whitelist: settings.dig(:add, :whitelist)
55
+
56
+ runner.run(action: :add) { |file| info "Processed: #{file}." }
54
57
  end
55
58
 
56
59
  desc "-r, [--remove=PATH]", "Remove pragma comments from source file(s)."
@@ -62,19 +65,23 @@ module Pragmater
62
65
  default: []
63
66
  method_option :whitelist,
64
67
  aliases: "-w",
65
- desc: "File extension whitelist",
68
+ desc: "File whitelist",
66
69
  type: :array,
67
70
  default: []
68
- def remove path
71
+ def remove path = "."
69
72
  settings = self.class.configuration.merge remove: {
70
73
  comments: options[:comments],
71
74
  whitelist: options[:whitelist]
72
75
  }
73
76
 
74
- write path, settings, :remove
77
+ runner = Runner.new path,
78
+ comments: settings.dig(:remove, :comments),
79
+ whitelist: settings.dig(:remove, :whitelist)
80
+
81
+ runner.run(action: :remove) { |file| info "Processed: #{file}." }
75
82
  end
76
83
 
77
- desc "-c, [--config]", %(Manage gem configuration ("#{configuration.computed_path}").)
84
+ desc "-c, [--config]", "Manage gem configuration."
78
85
  map %w[-c --config] => :config
79
86
  method_option :edit,
80
87
  aliases: "-e",
@@ -85,10 +92,11 @@ module Pragmater
85
92
  desc: "Print gem configuration.",
86
93
  type: :boolean, default: false
87
94
  def config
88
- path = self.class.configuration.computed_path
95
+ path = self.class.configuration.path
89
96
 
90
97
  if options.edit? then `#{editor} #{path}`
91
- elsif options.info? then say(path)
98
+ elsif options.info?
99
+ path ? say(path) : say("Configuration doesn't exist.")
92
100
  else help(:config)
93
101
  end
94
102
  end
@@ -104,42 +112,5 @@ module Pragmater
104
112
  def help task = nil
105
113
  say and super
106
114
  end
107
-
108
- private
109
-
110
- def whitelisted_files path, whitelist
111
- file_filter = whitelist.empty? ? %(#{path}/**/*) : %(#{path}/**/*{#{whitelist.join ","}})
112
- Pathname.glob(file_filter).select(&:file?)
113
- end
114
-
115
- def update_file path, comments, action
116
- Writer.new(path, comments).public_send action
117
- info "Processed: #{path}."
118
- rescue ArgumentError => error
119
- formatted_message = error.message
120
- formatted_message[0] = formatted_message[0].capitalize
121
- error "#{formatted_message}: #{path}."
122
- end
123
-
124
- # rubocop:disable Metrics/ParameterLists
125
- def update_files path, comments, whitelist, action
126
- if path.file?
127
- update_file path, comments, action
128
- elsif path.directory?
129
- whitelisted_files(path, whitelist).each do |file_path|
130
- update_file file_path, comments, action
131
- end
132
- else
133
- error %(Invalid source path: "#{path}".)
134
- end
135
- end
136
-
137
- def write path, settings, action
138
- pathname = Pathname path
139
- comments = Array settings.dig(action).dig(:comments)
140
- whitelist = Array settings.dig(action).dig(:whitelist)
141
-
142
- update_files pathname, comments, whitelist, action
143
- end
144
115
  end
145
116
  end
@@ -43,9 +43,11 @@ module Pragmater
43
43
  end
44
44
 
45
45
  def format
46
+ klass = self.class
47
+
46
48
  case string
47
- when self.class.shebang_format then format_shebang
48
- when self.class.pragma_format then format_pragma
49
+ when klass.shebang_format then format_shebang
50
+ when klass.pragma_format then format_pragma
49
51
  else string
50
52
  end
51
53
  end
@@ -12,15 +12,11 @@ module Pragmater
12
12
  end
13
13
 
14
14
  def self.version
15
- "3.1.0"
15
+ "4.0.0"
16
16
  end
17
17
 
18
18
  def self.version_label
19
19
  "#{label} #{version}"
20
20
  end
21
-
22
- def self.file_name
23
- ".#{name}rc"
24
- end
25
21
  end
26
22
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ # Adds/removes pragma comments for files in given path.
5
+ class Runner
6
+ # rubocop:disable Metrics/ParameterLists
7
+ def initialize path = ".", comments: [], whitelist: [], writer: Writer
8
+ @path = Pathname path
9
+ @comments = Array comments
10
+ @whitelist = Array whitelist
11
+ @writer = writer
12
+ end
13
+
14
+ def files
15
+ return [] unless path.exist? && path.directory? && !whitelist.empty?
16
+ Pathname.glob(%(#{path}/{#{whitelist.join ","}})).select(&:file?)
17
+ end
18
+
19
+ def run action:
20
+ files.each do |file|
21
+ writer.new(file, comments).public_send action
22
+ yield file if block_given?
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :path, :comments, :whitelist, :writer
29
+ end
30
+ end
@@ -2,11 +2,13 @@
2
2
 
3
3
  module Pragmater
4
4
  # Writes formatted pragma comments to source file.
5
+ # :reek:TooManyInstanceVariables
6
+ # :reek:PrimaDonnaMethod
5
7
  class Writer
6
8
  # rubocop:disable Metrics/ParameterLists
7
9
  def initialize file_path, new_comments, formatter: Formatter, commenter: Commenter
8
10
  @file_path = file_path
9
- @file_lines = File.open(file_path, &:to_a)
11
+ @file_lines = File.readlines file_path
10
12
  @formatter = formatter
11
13
  @commenter = commenter
12
14
  @old_comments = file_comments
@@ -38,17 +40,23 @@ module Pragmater
38
40
  file_lines.reject { |line| old_comments.include? line }
39
41
  end
40
42
 
43
+ # :reek:UtilityFunction
41
44
  def format lines
42
45
  lines.map { |line| "#{line}\n" }
43
46
  end
44
47
 
48
+ # :reek:UtilityFunction
45
49
  def insert_spacing! lines, comments
50
+ comment_count = comments.size
51
+
46
52
  return if comments.empty?
47
53
  return if lines.size == 1
48
- return if lines[comments.size] == "\n"
49
- lines.insert comments.size, "\n"
54
+ return if lines[comment_count] == "\n"
55
+
56
+ lines.insert comment_count, "\n"
50
57
  end
51
58
 
59
+ # :reek:UtilityFunction
52
60
  def remove_spacing! lines
53
61
  lines.delete_at(0) if lines.first == "\n"
54
62
  end
data/lib/pragmater.rb CHANGED
@@ -4,4 +4,5 @@ require "pragmater/identity"
4
4
  require "pragmater/formatter"
5
5
  require "pragmater/commenter"
6
6
  require "pragmater/writer"
7
+ require "pragmater/runner"
7
8
  require "pragmater/cli"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragmater
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-06 00:00:00.000000000 Z
11
+ date: 2017-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.6'
47
+ version: '1.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.6'
54
+ version: '1.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '12.0'
69
- - !ruby/object:Gem::Dependency
70
- name: gemsmith
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '9.4'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '9.4'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: pry
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -212,28 +198,28 @@ dependencies:
212
198
  requirements:
213
199
  - - "~>"
214
200
  - !ruby/object:Gem::Version
215
- version: '4.6'
201
+ version: '4.7'
216
202
  type: :development
217
203
  prerelease: false
218
204
  version_requirements: !ruby/object:Gem::Requirement
219
205
  requirements:
220
206
  - - "~>"
221
207
  - !ruby/object:Gem::Version
222
- version: '4.6'
208
+ version: '4.7'
223
209
  - !ruby/object:Gem::Dependency
224
210
  name: rubocop
225
211
  requirement: !ruby/object:Gem::Requirement
226
212
  requirements:
227
213
  - - "~>"
228
214
  - !ruby/object:Gem::Version
229
- version: '0.48'
215
+ version: '0.49'
230
216
  type: :development
231
217
  prerelease: false
232
218
  version_requirements: !ruby/object:Gem::Requirement
233
219
  requirements:
234
220
  - - "~>"
235
221
  - !ruby/object:Gem::Version
236
- version: '0.48'
222
+ version: '0.49'
237
223
  - !ruby/object:Gem::Dependency
238
224
  name: codeclimate-test-reporter
239
225
  requirement: !ruby/object:Gem::Requirement
@@ -266,6 +252,7 @@ files:
266
252
  - lib/pragmater/commenter.rb
267
253
  - lib/pragmater/formatter.rb
268
254
  - lib/pragmater/identity.rb
255
+ - lib/pragmater/runner.rb
269
256
  - lib/pragmater/writer.rb
270
257
  homepage: https://github.com/bkuhlmann/pragmater
271
258
  licenses: