namespacer-rb 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/namespacer +28 -9
- data/lib/namespacer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d185c337c9121c5caa1b0d5c8050189b5dc7f4bdb2711335eeb1b508a617b4ef
|
4
|
+
data.tar.gz: 34021011d450232a6222b0ba9c6de5f80c6909d487ba733d550e2ff95c02cfd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
-
|
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
|
data/lib/namespacer/version.rb
CHANGED