namespacer-rb 0.1.5 → 0.1.6

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: d185c337c9121c5caa1b0d5c8050189b5dc7f4bdb2711335eeb1b508a617b4ef
4
+ data.tar.gz: 34021011d450232a6222b0ba9c6de5f80c6909d487ba733d550e2ff95c02cfd3
5
5
  SHA512:
6
- metadata.gz: 3edf5bc7256392f0ecc35d50d3e1a491c1bb368f821062bc5466329c7c5568f3da746d80f356d7943c3c53b45b88a8a31908ad51dad1e14b0c784e20a2478bff
7
- data.tar.gz: deda785427a83e1eb9a2b66e3a91ec262c463f4e0a50b43abdfb068dd9197228c5b1d1cdf5ccb2d66b3fe4ce11634c174048800217820d121fbf5a30dc2ff02b
6
+ metadata.gz: 42884144adc93a87ee7af9da506ec51670d6289ef66b2f8ffcde00ab8eeafe40d0fa2e1f58c9239ff576438dddbc6cdb6910ce0b42cab060dae500147c40a248
7
+ data.tar.gz: 48421f57144fc65224be350c60a7ba8948851624c8d90bf36d218cab05f880075659c058757c7177dc6f68e4f9b8668d720692fe769d2c4bcadb5e7b0337cc01
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.6'
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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tj (bougyman) Vanderpoel