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