namespacer-rb 0.1.4 → 0.1.5
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/exe/namespacer +35 -13
- 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: 3e895d7e611b2619be7e4e0683066adb1776c186ddd8ea9d95e192a355e0f9ba
         | 
| 4 | 
            +
              data.tar.gz: e5f6405e2695170de3bc656f660b69f537d63c31d5ce2fca6ec1d64dd6796008
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3edf5bc7256392f0ecc35d50d3e1a491c1bb368f821062bc5466329c7c5568f3da746d80f356d7943c3c53b45b88a8a31908ad51dad1e14b0c784e20a2478bff
         | 
| 7 | 
            +
              data.tar.gz: deda785427a83e1eb9a2b66e3a91ec262c463f4e0a50b43abdfb068dd9197228c5b1d1cdf5ccb2d66b3fe4ce11634c174048800217820d121fbf5a30dc2ff02b
         | 
    
        data/exe/namespacer
    CHANGED
    
    | @@ -8,13 +8,13 @@ require 'tty-command' | |
| 8 8 | 
             
            module Rubyists
         | 
| 9 9 | 
             
              # Namespace for the namespacer CLI
         | 
| 10 10 | 
             
              module Namespacer
         | 
| 11 | 
            -
                CliOptions = Struct.new(:recursive, :verbose, :in_place)
         | 
| 11 | 
            +
                CliOptions = Struct.new(:recursive, :verbose, :in_place, :fail_rubocop_silently)
         | 
| 12 12 | 
             
                def self.cli_options
         | 
| 13 13 | 
             
                  @cli_options ||= CliOptions.new(verbose: false, recursive: false, in_place: false)
         | 
| 14 14 | 
             
                end
         | 
| 15 15 |  | 
| 16 16 | 
             
                def self.cmd
         | 
| 17 | 
            -
                  @cmd = TTY::Command.new
         | 
| 17 | 
            +
                  @cmd = TTY::Command.new printer: :null
         | 
| 18 18 | 
             
                end
         | 
| 19 19 | 
             
              end
         | 
| 20 20 | 
             
            end
         | 
| @@ -28,6 +28,10 @@ parser = OptionParser.new do |opts| | |
| 28 28 |  | 
| 29 29 | 
             
              opts.on('-i', '--in-place', 'Modify files in-place') { |_| options.in_place = true }
         | 
| 30 30 |  | 
| 31 | 
            +
              opts.on('-f', '--fail-rubocop-silently', 'Write files even if they are not rubocop-friendly') do |_|
         | 
| 32 | 
            +
                options.fail_rubocop_silently = true
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 31 35 | 
             
              opts.on('-V', '--version', 'Print version') do
         | 
| 32 36 | 
             
                puts "namespacer #{Rubyists::Namespacer::VERSION}"
         | 
| 33 37 | 
             
                exit
         | 
| @@ -74,21 +78,39 @@ def new_path(path) | |
| 74 78 | 
             
              dir.join("#{base}.namespaced#{ext}")
         | 
| 75 79 | 
             
            end
         | 
| 76 80 |  | 
| 77 | 
            -
            def  | 
| 81 | 
            +
            def rubocop_cmd(path, ruby_code) # rubocop:disable Metrics/MethodLength
         | 
| 82 | 
            +
              result = Rubyists::Namespacer.cmd.run!(:rubocop,
         | 
| 83 | 
            +
                                                     '-A',
         | 
| 84 | 
            +
                                                     '--stdin',
         | 
| 85 | 
            +
                                                     path.basename.to_s,
         | 
| 86 | 
            +
                                                     '--stderr',
         | 
| 87 | 
            +
                                                     input: ruby_code,
         | 
| 88 | 
            +
                                                     only_output_on_error: true)
         | 
| 89 | 
            +
              if result.failure?
         | 
| 90 | 
            +
                warn "Rubocop failed for #{path}:\n#{result.err}"
         | 
| 91 | 
            +
                if Rubyists::Namespacer.cli_options.fail_rubocop_silently
         | 
| 92 | 
            +
                  warn 'Continuing anyway'
         | 
| 93 | 
            +
                else
         | 
| 94 | 
            +
                  exit 6
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              result
         | 
| 99 | 
            +
            end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            def namespace_file(namespace, path) # rubocop:disable Metrics/MethodLength
         | 
| 102 | 
            +
              opts = Rubyists::Namespacer.cli_options
         | 
| 78 103 | 
             
              namespaced = Rubyists::Namespacer.namespace!(path.read, namespace)
         | 
| 79 | 
            -
              write_path =  | 
| 80 | 
            -
              if  | 
| 104 | 
            +
              write_path = opts.in_place ? path : new_path(path)
         | 
| 105 | 
            +
              if opts.verbose
         | 
| 81 106 | 
             
                msg = "Namespacing #{write_path} with #{namespace}"
         | 
| 82 | 
            -
                msg << ' (in-place)' if  | 
| 107 | 
            +
                msg << ' (in-place)' if opts.in_place
         | 
| 83 108 | 
             
                warn msg
         | 
| 84 109 | 
             
              end
         | 
| 85 | 
            -
              cmd =  | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
                                                 '--stderr',
         | 
| 90 | 
            -
                                                 input: namespaced,
         | 
| 91 | 
            -
                                                 only_output_on_error: true)
         | 
| 110 | 
            +
              cmd = rubocop_cmd(write_path, namespaced)
         | 
| 111 | 
            +
              return unless cmd&.success?
         | 
| 112 | 
            +
             | 
| 113 | 
            +
              warn "Writing namespaced file to #{write_path}" if opts.verbose
         | 
| 92 114 | 
             
              write_path.write(cmd.out)
         | 
| 93 115 | 
             
            end
         | 
| 94 116 |  | 
    
        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.5
         | 
| 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: ruby-filemagic
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0.7'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0.7'
         | 
| 27 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 42 | 
             
              name: tty-command
         | 
| 29 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         |