fedux_org-stdlib 0.2.1 → 0.3.0
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.
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'pathname'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module FeduxOrg
         
     | 
| 
       2 
4 
     | 
    
         
             
              module Stdlib
         
     | 
| 
       3 
5 
     | 
    
         
             
                module Command
         
     | 
| 
         @@ -16,15 +18,21 @@ module FeduxOrg 
     | 
|
| 
       16 
18 
     | 
    
         
             
                    # @return [String] 
         
     | 
| 
       17 
19 
     | 
    
         
             
                    #   path to command
         
     | 
| 
       18 
20 
     | 
    
         
             
                    def which(cmd, paths=ENV['PATH'].split(File::PATH_SEPARATOR), pathexts=ENV['PATHEXT'].to_s.split( /;/ ) )
         
     | 
| 
       19 
     | 
    
         
            -
                       
     | 
| 
      
 21 
     | 
    
         
            +
                      cmd = Pathname.new( cmd.to_s )
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                      return nil if cmd.to_s.empty?
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                      if cmd.absolute? 
         
     | 
| 
      
 26 
     | 
    
         
            +
                        return cmd.to_s if cmd.executable?
         
     | 
| 
      
 27 
     | 
    
         
            +
                        return nil
         
     | 
| 
      
 28 
     | 
    
         
            +
                      end
         
     | 
| 
       20 
29 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                      cmd = File.basename( cmd )
         
     | 
| 
       22 
30 
     | 
    
         
             
                      pathexts = [''] if pathexts.blank?
         
     | 
| 
       23 
31 
     | 
    
         | 
| 
       24 
32 
     | 
    
         
             
                      Array( paths ).each do |path|
         
     | 
| 
       25 
33 
     | 
    
         
             
                        Array( pathexts ).each do |ext|
         
     | 
| 
       26 
     | 
    
         
            -
                           
     | 
| 
       27 
     | 
    
         
            -
                          return  
     | 
| 
      
 34 
     | 
    
         
            +
                          file = Pathname.new( File.join(path, "#{cmd.to_s}#{ext.to_s}") )
         
     | 
| 
      
 35 
     | 
    
         
            +
                          return file.to_s if file.executable?
         
     | 
| 
       28 
36 
     | 
    
         
             
                        end
         
     | 
| 
       29 
37 
     | 
    
         
             
                      end                                                                                                                                                        
         
     | 
| 
       30 
38 
     | 
    
         
             
                      nil
         
     | 
    
        data/spec/command/which_spec.rb
    CHANGED
    
    | 
         @@ -17,6 +17,10 @@ describe Command::Which do 
     | 
|
| 
       17 
17 
     | 
    
         
             
                  expect( klass.new.which( '/usr/bin/which' ) ).to eq( '/usr/bin/which' )
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
      
 20 
     | 
    
         
            +
                it 'returns nil for a invalid command if a full path is given' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  expect( klass.new.which( '/usr/bin/which1' ) ).to eq( nil )
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
       20 
24 
     | 
    
         
             
                it 'returns nil if no executable can be found in path' do
         
     | 
| 
       21 
25 
     | 
    
         
             
                  expect( klass.new.which( 'asdfasdf' ) ).to eq( nil )
         
     | 
| 
       22 
26 
     | 
    
         
             
                end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: fedux_org-stdlib
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-12-04 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -190,18 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       190 
190 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       191 
191 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       192 
192 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       193 
     | 
    
         
            -
                  segments:
         
     | 
| 
       194 
     | 
    
         
            -
                  - 0
         
     | 
| 
       195 
     | 
    
         
            -
                  hash: 2589077551573371235
         
     | 
| 
       196 
193 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       197 
194 
     | 
    
         
             
              none: false
         
     | 
| 
       198 
195 
     | 
    
         
             
              requirements:
         
     | 
| 
       199 
196 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       200 
197 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       201 
198 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       202 
     | 
    
         
            -
                  segments:
         
     | 
| 
       203 
     | 
    
         
            -
                  - 0
         
     | 
| 
       204 
     | 
    
         
            -
                  hash: 2589077551573371235
         
     | 
| 
       205 
199 
     | 
    
         
             
            requirements: []
         
     | 
| 
       206 
200 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       207 
201 
     | 
    
         
             
            rubygems_version: 1.8.23
         
     |