fedux_org-stdlib 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,12 @@
1
+ begin
2
+ require 'active_support/core_ext/string/inflections'
3
+ require 'active_support/core_ext/object/blank'
4
+ rescue LoadError
5
+ $stderr.puts 'You need to install the "activesupport"-gem to make that library work.'
6
+ exit 1
7
+ end
8
+
1
9
  require 'open3'
2
- require 'active_support/core_ext/string/inflections'
3
- require 'active_support/core_ext/object/blank'
4
10
 
5
11
  require 'fedux_org/stdlib/environment'
6
12
  require 'fedux_org/stdlib/command/command_result'
@@ -54,18 +60,24 @@ module FeduxOrg
54
60
  # Search for command
55
61
  # @param [String] cmd
56
62
  # name of command or path to command (will be reduced to basename and then searched in PATH)
63
+ #
64
+ # @param [Array,String] paths
65
+ # a string containing paths separated by "File::PATH_SEPARATOR" or an array of paths
66
+ #
67
+ # @param [Array,String] pathexts
68
+ # a string containing pathexts separated by ";" or an array of pathexts
57
69
  #
58
70
  # @return [String]
59
71
  # path to command
60
- def which(cmd)
72
+ def which(cmd, paths=ENV['PATH'].split(File::PATH_SEPARATOR), pathexts=ENV['PATHEXT'].to_s.split( /;/ ) )
61
73
  return nil if cmd.blank?
62
74
 
63
75
  cmd = File.basename( cmd )
76
+ pathexts = [''] if pathexts.blank?
64
77
 
65
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
66
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
67
- exts.each do |ext|
68
- exe = File.join(path, "#{cmd}#{ext}")
78
+ Array( paths ).each do |path|
79
+ Array( pathexts ).each do |ext|
80
+ exe = File.join(path, "#{cmd}#{ext.to_s}")
69
81
  return exe if File.executable? exe
70
82
  end
71
83
  end
@@ -1,5 +1,11 @@
1
- require 'active_support/core_ext/string/inflections'
2
- require 'active_support/core_ext/object/blank'
1
+ begin
2
+ require 'active_support/core_ext/string/inflections'
3
+ require 'active_support/core_ext/object/blank'
4
+ rescue LoadError
5
+ $stderr.puts 'You need to install the "activesupport"-gem to make that library work.'
6
+ exit 1
7
+ end
8
+
3
9
  require 'fedux_org/stdlib/models/filesystem_based_model'
4
10
  require 'find'
5
11
 
@@ -1,4 +1,9 @@
1
- require 'yard'
1
+ begin
2
+ require 'yard'
3
+ rescue LoadError
4
+ $stderr.puts 'You need to install the "yard"-gem to make that rake task work.'
5
+ exit 1
6
+ end
2
7
 
3
8
  YARD::Rake::YardocTask.new() do |y|
4
9
  # y.options << '--verbose'
@@ -1,3 +1,8 @@
1
1
  namespace :gem do
2
- require 'bundler/gem_tasks'
2
+ begin
3
+ require 'bundler/gem_tasks'
4
+ rescue LoadError
5
+ $stderr.puts 'You need to install the "bundler"-gem to make that rake task work.'
6
+ exit 1
7
+ end
3
8
  end
@@ -1,7 +1,18 @@
1
1
  require_relative 'base'
2
2
 
3
- require 'active_support/core_ext/string/strip'
4
- require 'erubis'
3
+ begin
4
+ require 'active_support/core_ext/string/strip'
5
+ rescue LoadError
6
+ $stderr.puts 'You need to install the "activesupport"-gem to make that rake task work.'
7
+ exit 1
8
+ end
9
+
10
+ begin
11
+ require 'erubis'
12
+ rescue LoadError
13
+ $stderr.puts 'You need to install the "erubis"-gem to make that rake task work.'
14
+ exit 1
15
+ end
5
16
 
6
17
  namespace :version do
7
18
  desc 'bump version of library to new version'
@@ -1,6 +1,6 @@
1
1
  #main FeduxOrg
2
2
  module FeduxOrg
3
3
  module Stdlib
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
  end
data/spec/command_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe Command do
25
25
  end
26
26
  end
27
27
 
28
- context '#which' do
28
+ context '#which', :focus do
29
29
  klass = Class.new do
30
30
  include Command
31
31
  end
@@ -37,5 +37,25 @@ describe Command do
37
37
  it 'returns full path for a valid command although a full path is given' do
38
38
  expect( klass.new.which( '/usr/bin/which' ) ).to eq( '/usr/bin/which' )
39
39
  end
40
+
41
+ it 'returns nil if no executable can be found in path' do
42
+ expect( klass.new.which( 'asdfasdf' ) ).to eq( nil )
43
+ end
44
+
45
+ it 'uses paths string to search for command' do
46
+ expect( klass.new.which( 'which', '/usr/bin' ) ).to eq( '/usr/bin/which' )
47
+ end
48
+
49
+ it 'uses paths array to search for command' do
50
+ expect( klass.new.which( 'which', [ '/usr/bin' ] ) ).to eq( '/usr/bin/which' )
51
+ end
52
+
53
+ it 'uses pathexts to search for command' do
54
+ expect( klass.new.which( 'which', [ '/usr/bin' ], '' ) ).to eq( '/usr/bin/which' )
55
+ end
56
+
57
+ it 'uses pathexts array to search for command' do
58
+ expect( klass.new.which( 'which', [ '/usr/bin' ], [ '' ]) ).to eq( '/usr/bin/which' )
59
+ end
40
60
  end
41
61
  end
@@ -33,7 +33,7 @@ describe FeduxOrg::Stdlib::Logging::Logger do
33
33
  expect( bucket.string ).not_to include( 'Not visible' )
34
34
  end
35
35
 
36
- it 'changes the mode (log level) of the logger', :focus do
36
+ it 'changes the mode (log level) of the logger' do
37
37
  bucket = StringIO.new
38
38
 
39
39
  logger = FeduxOrg::Stdlib::Logging::Logger.new( Logger.new( bucket) )
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.1.1
4
+ version: 0.1.2
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-11-16 00:00:00.000000000 Z
12
+ date: 2013-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler