namespacer-rb 0.1.6 → 0.1.8
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 +4 -4
- data/Readme.adoc +1 -0
- data/exe/namespacer +9 -3
- data/lib/namespacer/version.rb +1 -1
- data/lib/namespacer.rb +4 -3
- 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: d9007d905c40b79426ef2e135e520bf0a87f035a2ae2413c06398d0e04d91f73
|
4
|
+
data.tar.gz: a43de5cd8ca7bde19071109dc171ee7b534647ff2d5c0729e15ad1b5410874f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bafd3deefcd88b7c476aa295fc7d6134e7d0e0ca0589077a24fda966b401fd3a5f6e3832832092e24723f1ea63940113b28479e6322efdd9dcb94a00df79bc35
|
7
|
+
data.tar.gz: b47c888e929e11a25c6990a9578cd04c57d9da8250268a4787243013178b297f30b73bd0bb33faef05300df4e4eb249304f6b342a8984fe34809a34ce1b9e09c
|
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
@@ -9,7 +9,7 @@ require 'tty-command'
|
|
9
9
|
module Rubyists
|
10
10
|
# Namespace for the namespacer CLI
|
11
11
|
module Namespacer
|
12
|
-
CliOptions = Struct.new(:recursive, :verbose, :in_place, :fail_rubocop_silently)
|
12
|
+
CliOptions = Struct.new(:recursive, :verbose, :in_place, :fail_rubocop_silently, :allow_text_files)
|
13
13
|
def self.cli_options
|
14
14
|
@cli_options ||= CliOptions.new(verbose: false, recursive: false, in_place: false)
|
15
15
|
end
|
@@ -33,6 +33,10 @@ parser = OptionParser.new do |opts|
|
|
33
33
|
|
34
34
|
opts.on('-i', '--in-place', 'Modify files in-place') { |_| options.in_place = true }
|
35
35
|
|
36
|
+
opts.on('-a', '--allow-text-files', 'Allow non-ruby mime types, so long as they are text') do |_|
|
37
|
+
options.allow_text_files = true
|
38
|
+
end
|
39
|
+
|
36
40
|
opts.on('-f', '--fail-rubocop-silently', 'Write files even if they are not rubocop-friendly') do |_|
|
37
41
|
options.fail_rubocop_silently = true
|
38
42
|
end
|
@@ -80,7 +84,7 @@ def new_path(path)
|
|
80
84
|
dir = path.dirname
|
81
85
|
ext = path.extname
|
82
86
|
base = path.basename(ext.to_s)
|
83
|
-
dir.join("#{base}
|
87
|
+
dir.join("#{base}_namespaced#{ext}")
|
84
88
|
end
|
85
89
|
|
86
90
|
def rubocop_cmd(path, ruby_code) # rubocop:disable Metrics/MethodLength
|
@@ -104,11 +108,13 @@ def rubocop_cmd(path, ruby_code) # rubocop:disable Metrics/MethodLength
|
|
104
108
|
end
|
105
109
|
|
106
110
|
def rubocop_friendly?(path)
|
111
|
+
opts = Rubyists::Namespacer.cli_options
|
107
112
|
magic = Rubyists::Namespacer.magic
|
108
113
|
mime = magic.file(path.to_s)
|
109
114
|
return true if mime.include?('text/x-ruby')
|
115
|
+
return true if mime.split('/').first == 'text' && opts.allow_text_files
|
110
116
|
|
111
|
-
warn "File #{path} is not a Ruby file (#{mime})" if
|
117
|
+
warn "File #{path} is not a Ruby file (#{mime})" if opts.verbose
|
112
118
|
false
|
113
119
|
end
|
114
120
|
|
data/lib/namespacer/version.rb
CHANGED
data/lib/namespacer.rb
CHANGED
@@ -7,9 +7,9 @@ require 'pry'
|
|
7
7
|
|
8
8
|
# Top-level namespace to keep Rubyists namespaces in isolation
|
9
9
|
module Rubyists
|
10
|
-
#
|
10
|
+
# Namespace for the namespacer tool
|
11
11
|
module Namespacer
|
12
|
-
# Do the rewriting with the
|
12
|
+
# Do the AST rewriting with the Rewriter class
|
13
13
|
class Rewriter < Parser::TreeRewriter
|
14
14
|
attr_accessor(:namespaces)
|
15
15
|
|
@@ -44,6 +44,7 @@ module Rubyists
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
# Wrap some namespace around top-level AST nodes of 'module' or 'class' type
|
47
48
|
def self.namespace!(string_or_io, namespaces)
|
48
49
|
buffer = Parser::Source::Buffer.new("(#{namespaces})")
|
49
50
|
buffer.source = string_or_io.is_a?(IO) ? string_or_io.read : string_or_io
|
@@ -56,5 +57,5 @@ end
|
|
56
57
|
|
57
58
|
if $PROGRAM_NAME == __FILE__
|
58
59
|
warn 'Wrapping myself'
|
59
|
-
puts Rubyists::Namespacer.namespace!(File.read(__FILE__), '
|
60
|
+
puts Rubyists::Namespacer.namespace!(File.read(__FILE__), 'Wrapped::Smoke::Test')
|
60
61
|
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.
|
4
|
+
version: 0.1.8
|
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
|