namespacer-rb 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e895d7e611b2619be7e4e0683066adb1776c186ddd8ea9d95e192a355e0f9ba
4
- data.tar.gz: e5f6405e2695170de3bc656f660b69f537d63c31d5ce2fca6ec1d64dd6796008
3
+ metadata.gz: 80c1319eb56d8321d3acacca45c0e724378f49c287f3447f22a709d3c8dfebec
4
+ data.tar.gz: 7b0c82bb2371409a298fd90bdbb15b655ca7e113600448cdd62a4a0a19ae80f1
5
5
  SHA512:
6
- metadata.gz: 3edf5bc7256392f0ecc35d50d3e1a491c1bb368f821062bc5466329c7c5568f3da746d80f356d7943c3c53b45b88a8a31908ad51dad1e14b0c784e20a2478bff
7
- data.tar.gz: deda785427a83e1eb9a2b66e3a91ec262c463f4e0a50b43abdfb068dd9197228c5b1d1cdf5ccb2d66b3fe4ce11634c174048800217820d121fbf5a30dc2ff02b
6
+ metadata.gz: 7a8679263fad4f27695766449de5f6a01c0111bbea1f818607ed3c1565d219b88da75469fe6ffc1e4fe2dad7d352b7c4fbb5e09d0e30c50e1640b7ad7a8bf81c
7
+ data.tar.gz: b0e8bb9897e55062169f119fb7a684ab6549cdc3a085b1bcb61d2b88b9869a9cd2e26f9d6b44142316f36ae09990c0ef0b59e476b72b72902961f0d39e85081d
data/Readme.adoc CHANGED
@@ -25,6 +25,7 @@ gem install namespacer-rb
25
25
  ### Namespacing a file
26
26
 
27
27
  `namespacer MyNamespace my_file.rb` will create a new file `my_file.namespaced.rb` with all top-level classes and modules namespaced under `MyNamespace`.
28
+ `namespacer -i MyNamespace my_file.rb` will overwrite the original file with the namespaced version.
28
29
 
29
30
  ## Development
30
31
 
data/exe/namespacer CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'filemagic'
4
5
  require 'namespacer'
5
6
  require 'optparse'
6
7
  require 'pathname'
@@ -14,7 +15,11 @@ module Rubyists
14
15
  end
15
16
 
16
17
  def self.cmd
17
- @cmd = TTY::Command.new printer: :null
18
+ @cmd ||= TTY::Command.new printer: :null
19
+ end
20
+
21
+ def self.magic
22
+ @magic ||= FileMagic.new(FileMagic::MAGIC_MIME)
18
23
  end
19
24
  end
20
25
  end
@@ -98,18 +103,32 @@ def rubocop_cmd(path, ruby_code) # rubocop:disable Metrics/MethodLength
98
103
  result
99
104
  end
100
105
 
101
- def namespace_file(namespace, path) # rubocop:disable Metrics/MethodLength
106
+ def rubocop_friendly?(path)
107
+ magic = Rubyists::Namespacer.magic
108
+ mime = magic.file(path.to_s)
109
+ return true if mime.include?('text/x-ruby')
110
+
111
+ warn "File #{path} is not a Ruby file (#{mime})" if Rubyists::Namespacer.cli_options.verbose
112
+ false
113
+ end
114
+
115
+ def log_namespace(namespace, write_path)
116
+ opts = Rubyists::Namespacer.cli_options
117
+ return unless opts.verbose
118
+
119
+ msg = "Namespacing #{write_path} with #{namespace}"
120
+ msg << ' (in-place)' if opts.in_place
121
+ warn msg
122
+ end
123
+
124
+ def namespace_file(namespace, path)
125
+ return unless rubocop_friendly?(path)
126
+
102
127
  opts = Rubyists::Namespacer.cli_options
103
128
  namespaced = Rubyists::Namespacer.namespace!(path.read, namespace)
104
129
  write_path = opts.in_place ? path : new_path(path)
105
- if opts.verbose
106
- msg = "Namespacing #{write_path} with #{namespace}"
107
- msg << ' (in-place)' if opts.in_place
108
- warn msg
109
- end
130
+ log_namespace namespace, write_path
110
131
  cmd = rubocop_cmd(write_path, namespaced)
111
- return unless cmd&.success?
112
-
113
132
  warn "Writing namespaced file to #{write_path}" if opts.verbose
114
133
  write_path.write(cmd.out)
115
134
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubyists
4
4
  module Namespacer
5
- VERSION = '0.1.5'
5
+ VERSION = '0.1.7'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namespacer-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tj (bougyman) Vanderpoel
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.21'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.21'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: ruby-filemagic
29
43
  requirement: !ruby/object:Gem::Requirement