namespacer-rb 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80c1319eb56d8321d3acacca45c0e724378f49c287f3447f22a709d3c8dfebec
4
- data.tar.gz: 7b0c82bb2371409a298fd90bdbb15b655ca7e113600448cdd62a4a0a19ae80f1
3
+ metadata.gz: d9007d905c40b79426ef2e135e520bf0a87f035a2ae2413c06398d0e04d91f73
4
+ data.tar.gz: a43de5cd8ca7bde19071109dc171ee7b534647ff2d5c0729e15ad1b5410874f1
5
5
  SHA512:
6
- metadata.gz: 7a8679263fad4f27695766449de5f6a01c0111bbea1f818607ed3c1565d219b88da75469fe6ffc1e4fe2dad7d352b7c4fbb5e09d0e30c50e1640b7ad7a8bf81c
7
- data.tar.gz: b0e8bb9897e55062169f119fb7a684ab6549cdc3a085b1bcb61d2b88b9869a9cd2e26f9d6b44142316f36ae09990c0ef0b59e476b72b72902961f0d39e85081d
6
+ metadata.gz: bafd3deefcd88b7c476aa295fc7d6134e7d0e0ca0589077a24fda966b401fd3a5f6e3832832092e24723f1ea63940113b28479e6322efdd9dcb94a00df79bc35
7
+ data.tar.gz: b47c888e929e11a25c6990a9578cd04c57d9da8250268a4787243013178b297f30b73bd0bb33faef05300df4e4eb249304f6b342a8984fe34809a34ce1b9e09c
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}.namespaced#{ext}")
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 Rubyists::Namespacer.cli_options.verbose
117
+ warn "File #{path} is not a Ruby file (#{mime})" if opts.verbose
112
118
  false
113
119
  end
114
120
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubyists
4
4
  module Namespacer
5
- VERSION = '0.1.7'
5
+ VERSION = '0.1.8'
6
6
  end
7
7
  end
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
- # Wrap some namespace around top-level AST nodes of 'module' or 'class' type
10
+ # Namespace for the namespacer tool
11
11
  module Namespacer
12
- # Do the rewriting with the rewriter class
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__), 'Rubyists::Namespacer')
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tj (bougyman) Vanderpoel