sanky-pf 0.1.2 → 0.1.3
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/lib/sanky/pathfinder/finder.rb +63 -0
- data/lib/sanky/pathfinder/options.rb +40 -0
- data/lib/sanky/pathfinder/runner.rb +17 -0
- data/lib/sanky/pathfinder/version.rb +5 -0
- metadata +6 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cb5025e0020619040fe09a5e1f64f4fba531b002
         | 
| 4 | 
            +
              data.tar.gz: 7d9eb8daf257df0134f23987e925226d114b2067
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4034f3c15615751f5b193a413fb3f9bae4365b0b141b45401a746eda16d356b437f85aee68a4bf5a00c490a631e6a729477665d51738b17e92c360d9a345c38b
         | 
| 7 | 
            +
              data.tar.gz: ab05d7e91befadd281ae065f16afc1435eace6763afd193fa5c9540c9b36be7b046a2e873a2ddb9b03cb409a521aa314fb343ad1b9c745580701d9df37ecec0f
         | 
| @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            require 'colorize'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Sanky
         | 
| 4 | 
            +
              module PathFinder
         | 
| 5 | 
            +
                class Finder
         | 
| 6 | 
            +
                  def initialize(arguments)
         | 
| 7 | 
            +
                    @found     = nil
         | 
| 8 | 
            +
                    @arguments = arguments
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def to_s
         | 
| 12 | 
            +
                    @arguments
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def convert
         | 
| 16 | 
            +
                    @arguments.map! do |original|
         | 
| 17 | 
            +
                      set = Hash.new()
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                      # subsitute windows backslashes for forwardslashes and strip whitespace, add leading forwardslash, and /Volumes prefix
         | 
| 20 | 
            +
                      set[:original] = original.strip.gsub(/\\/, "/")
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                      drive = /.{1,3}:/
         | 
| 23 | 
            +
                      # are we talking about sankynet or sanky direct drives here? let's try both.
         | 
| 24 | 
            +
                      if original.match(drive)
         | 
| 25 | 
            +
                        set[:sanky_net]    = set[:original].sub(drive, "/Volumes/SankyNet Drive")
         | 
| 26 | 
            +
                        set[:sanky_direct] = set[:original].sub(drive, "/Volumes/Sanky Direct Drive/Sanky Shared")
         | 
| 27 | 
            +
                      else
         | 
| 28 | 
            +
                        set[:volume]  = set[:original].sub(/^(?!\/Volumes)/i, "/Volumes/")
         | 
| 29 | 
            +
                      end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                      set.map { |key, value| value.gsub!(/\/\//, "/") }
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                      set
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    self
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  def open
         | 
| 40 | 
            +
                    @arguments.each do |target|
         | 
| 41 | 
            +
                      target.each do |drive, file|
         | 
| 42 | 
            +
                        unless @found
         | 
| 43 | 
            +
                          begin
         | 
| 44 | 
            +
                            # pipe STDERR to dev null in favor of custom prompt
         | 
| 45 | 
            +
                            `open -g '#{file}' > /dev/null 2>/dev/null`
         | 
| 46 | 
            +
                          ensure
         | 
| 47 | 
            +
                            if $? == 0
         | 
| 48 | 
            +
                              @found = true
         | 
| 49 | 
            +
                              puts "Opening the file in the background...".yellow
         | 
| 50 | 
            +
                            else
         | 
| 51 | 
            +
                              puts "Failed to find #{file}!".red
         | 
| 52 | 
            +
                              puts "Trying another likely location...".red
         | 
| 53 | 
            +
                            end
         | 
| 54 | 
            +
                          end
         | 
| 55 | 
            +
                        end
         | 
| 56 | 
            +
                      end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                      puts "Hope you got lucky!".green
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            require 'optparse'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Sanky
         | 
| 4 | 
            +
              module PathFinder
         | 
| 5 | 
            +
                class Options
         | 
| 6 | 
            +
                  attr_reader :arguments
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize(argv)
         | 
| 9 | 
            +
                    parse(argv)
         | 
| 10 | 
            +
                    @arguments = argv
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                private
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def parse(argv)
         | 
| 16 | 
            +
                    OptionParser.new do |opts|
         | 
| 17 | 
            +
                      opts.banner = "Usage: sanky-pf file [ file ] ..."
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                      opts.on("-h", "--help", "Show this message") do
         | 
| 20 | 
            +
                        puts opts
         | 
| 21 | 
            +
                        exit
         | 
| 22 | 
            +
                      end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                      opts.on("-v", "--version", "Display the package version") do
         | 
| 25 | 
            +
                        puts Sanky::PathFinder::VERSION
         | 
| 26 | 
            +
                        exit
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                      begin
         | 
| 30 | 
            +
                        argv = ["-h"] if argv.empty?
         | 
| 31 | 
            +
                        opts.parse!(argv)
         | 
| 32 | 
            +
                      rescue OptionParser::ParseError => e
         | 
| 33 | 
            +
                        STDERR.puts e.message, "\n", opts
         | 
| 34 | 
            +
                        exit(1)
         | 
| 35 | 
            +
                      end
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            require_relative 'options'
         | 
| 2 | 
            +
            require_relative 'finder'
         | 
| 3 | 
            +
            require_relative 'version'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Sanky
         | 
| 6 | 
            +
              module PathFinder
         | 
| 7 | 
            +
                class Runner
         | 
| 8 | 
            +
                  def initialize(argv)
         | 
| 9 | 
            +
                    @options = Options.new(argv)
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def run
         | 
| 13 | 
            +
                    Sanky::PathFinder::Finder.new(@options.arguments).convert.open
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sanky-pf
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Matt Ryan
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-01- | 
| 11 | 
            +
            date: 2014-01-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: colorize
         | 
| @@ -55,6 +55,10 @@ extensions: [] | |
| 55 55 | 
             
            extra_rdoc_files: []
         | 
| 56 56 | 
             
            files:
         | 
| 57 57 | 
             
            - bin/sanky-pf
         | 
| 58 | 
            +
            - lib/sanky/pathfinder/finder.rb
         | 
| 59 | 
            +
            - lib/sanky/pathfinder/options.rb
         | 
| 60 | 
            +
            - lib/sanky/pathfinder/runner.rb
         | 
| 61 | 
            +
            - lib/sanky/pathfinder/version.rb
         | 
| 58 62 | 
             
            - test/test_finder.rb
         | 
| 59 63 | 
             
            - test/test_options.rb
         | 
| 60 64 | 
             
            homepage: https://github.com/sankynet/sankypf
         |