fedux_org-stdlib 0.3.0 → 0.3.2
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,5 +1,12 @@
|
|
|
1
1
|
require 'pathname'
|
|
2
2
|
|
|
3
|
+
begin
|
|
4
|
+
require 'active_support/core_ext/object/blank'
|
|
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
|
+
|
|
3
10
|
module FeduxOrg
|
|
4
11
|
module Stdlib
|
|
5
12
|
module Command
|
|
@@ -17,13 +24,28 @@ module FeduxOrg
|
|
|
17
24
|
#
|
|
18
25
|
# @return [String]
|
|
19
26
|
# path to command
|
|
20
|
-
def which(cmd,
|
|
21
|
-
|
|
27
|
+
def which(cmd, options={})
|
|
28
|
+
options = {
|
|
29
|
+
paths: ENV['PATH'].split(File::PATH_SEPARATOR),
|
|
30
|
+
pathexts: ENV['PATHEXT'].to_s.split( /;/ ),
|
|
31
|
+
raise_error_on_not_executable: false,
|
|
32
|
+
raise_error_on_not_found: false,
|
|
33
|
+
}.merge options
|
|
34
|
+
|
|
35
|
+
cmd = Pathname.new(cmd)
|
|
36
|
+
|
|
37
|
+
paths = options[:paths]
|
|
38
|
+
pathexts = options[:pathexts]
|
|
39
|
+
raise_error_on_not_executable = options[:raise_error_on_not_executable]
|
|
40
|
+
raise_error_on_not_found = options[:raise_error_on_not_found]
|
|
22
41
|
|
|
42
|
+
raise Exceptions::CommandNotFound if cmd.to_s.empty?
|
|
23
43
|
return nil if cmd.to_s.empty?
|
|
24
44
|
|
|
25
45
|
if cmd.absolute?
|
|
26
46
|
return cmd.to_s if cmd.executable?
|
|
47
|
+
raise Exceptions::CommandNotFound if raise_error_on_not_found and not cmd.exist?
|
|
48
|
+
raise Exceptions::CommandNotExecutable if raise_error_on_not_executable and not cmd.executable?
|
|
27
49
|
return nil
|
|
28
50
|
end
|
|
29
51
|
|
|
@@ -33,8 +55,10 @@ module FeduxOrg
|
|
|
33
55
|
Array( pathexts ).each do |ext|
|
|
34
56
|
file = Pathname.new( File.join(path, "#{cmd.to_s}#{ext.to_s}") )
|
|
35
57
|
return file.to_s if file.executable?
|
|
58
|
+
raise Exceptions::CommandNotExecutable if raise_error_on_not_executable and not cmd.executable?
|
|
36
59
|
end
|
|
37
60
|
end
|
|
61
|
+
raise Exceptions::CommandNotFound if raise_error_on_not_found
|
|
38
62
|
nil
|
|
39
63
|
end
|
|
40
64
|
end
|
|
@@ -44,6 +44,7 @@ module FeduxOrg
|
|
|
44
44
|
def switch_to_working_directory(&block)
|
|
45
45
|
Dir.chdir(working_directory, &block)
|
|
46
46
|
end
|
|
47
|
+
alias_method :in_working_directory, :switch_to_working_directory
|
|
47
48
|
|
|
48
49
|
# Create directory(ies)
|
|
49
50
|
#
|
|
@@ -204,7 +205,7 @@ module FeduxOrg
|
|
|
204
205
|
strings = []
|
|
205
206
|
regex = %r[\.\.]
|
|
206
207
|
|
|
207
|
-
raise FileSystem::Exceptions::InvalidPath , "Sorry, but you cannot use paths matching \"#{strings.join(', ')}\" or \"#{regex.
|
|
208
|
+
raise FileSystem::Exceptions::InvalidPath , "Sorry, but you cannot use paths matching \"#{strings.join(', ')}\" or \"#{regex.inspect}\" here!" if path_matches?(strings, regex, flattend_paths)
|
|
208
209
|
end
|
|
209
210
|
|
|
210
211
|
# Check if path is forbidden for delete operation
|
|
@@ -101,12 +101,12 @@ module FeduxOrg
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
#finds a single instance
|
|
104
|
-
def find(
|
|
105
|
-
find_all(
|
|
104
|
+
def find(criteria = {})
|
|
105
|
+
find_all(criteria).first
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
#finds all instances
|
|
109
|
-
def find_all(
|
|
109
|
+
def find_all(criteria = {})
|
|
110
110
|
FeduxOrg::Stdlib.logger.debug(self) { "Criteria for search: #{ criteria }" }
|
|
111
111
|
criteria = { name: criteria.to_sym } if criteria.kind_of? Symbol or criteria.kind_of? String
|
|
112
112
|
|
|
@@ -21,35 +21,42 @@ unless ENV.to_hash.has_key? 'CI'
|
|
|
21
21
|
namespace :version do
|
|
22
22
|
@logger = FeduxOrg::Stdlib::Logging::Logger.new
|
|
23
23
|
|
|
24
|
-
def
|
|
24
|
+
def add_to_repo(file, version)
|
|
25
|
+
@logger.info('Adding new version file to repository.')
|
|
26
|
+
sh "git add #{file}"
|
|
27
|
+
sh "git commit -m 'version bump to #{version}'"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def bump_version(type)
|
|
25
31
|
version_update do |file|
|
|
26
|
-
file.bump(
|
|
32
|
+
file.bump(type)
|
|
27
33
|
end
|
|
28
34
|
end
|
|
29
35
|
|
|
30
|
-
def version_update(
|
|
31
|
-
file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.read(
|
|
36
|
+
def version_update(&block)
|
|
37
|
+
file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.read(version_file)
|
|
32
38
|
old_version = file.version
|
|
33
|
-
block.call(
|
|
39
|
+
block.call(file)
|
|
34
40
|
new_version = file.version
|
|
35
41
|
|
|
36
|
-
file.write(
|
|
37
|
-
@logger.info(
|
|
42
|
+
file.write(version_file)
|
|
43
|
+
@logger.info("Updated version. It was \"#{old_version}\". It is now \"#{new_version}\".")
|
|
44
|
+
add_to_repo(version_file, file.version)
|
|
38
45
|
end
|
|
39
46
|
|
|
40
47
|
desc "Bump x.1.1"
|
|
41
48
|
task :bump_major do
|
|
42
|
-
bump_version(
|
|
49
|
+
bump_version(:major)
|
|
43
50
|
end
|
|
44
51
|
|
|
45
52
|
desc "Bump 1.x.1"
|
|
46
53
|
task :bump_minor do
|
|
47
|
-
bump_version(
|
|
54
|
+
bump_version(:minor)
|
|
48
55
|
end
|
|
49
56
|
|
|
50
57
|
desc "Bump 1.1.x"
|
|
51
58
|
task :bump_tiny do
|
|
52
|
-
bump_version(
|
|
59
|
+
bump_version(:tiny)
|
|
53
60
|
end
|
|
54
61
|
|
|
55
62
|
desc 'bump version of library to new version'
|
|
@@ -60,14 +67,11 @@ unless ENV.to_hash.has_key? 'CI'
|
|
|
60
67
|
begin
|
|
61
68
|
version_update do |file|
|
|
62
69
|
file.version = new_version
|
|
63
|
-
file.write(
|
|
64
|
-
|
|
65
|
-
@logger.info( 'Adding new version file to repository.' )
|
|
66
|
-
sh "git add #{version_file}"
|
|
67
|
-
sh "git commit -m 'version bump to #{new_version}'"
|
|
70
|
+
file.write(version_file)
|
|
71
|
+
add_to_repo(version_file, new_version)
|
|
68
72
|
end
|
|
69
73
|
rescue
|
|
70
|
-
@logger.fatal(
|
|
74
|
+
@logger.fatal('Nothing has changed since your last commit or has been added to the index. Therefor nothing needs to be commited.')
|
|
71
75
|
end
|
|
72
76
|
end
|
|
73
77
|
end
|
data/spec/command/which_spec.rb
CHANGED
|
@@ -10,35 +10,35 @@ describe Command::Which do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it 'returns full path for a valid command' do
|
|
13
|
-
expect(
|
|
13
|
+
expect(klass.new.which( 'which' )).to eq( '/usr/bin/which' )
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it 'returns full path for a valid command although a full path is given' do
|
|
17
|
-
expect(
|
|
17
|
+
expect(klass.new.which( '/usr/bin/which' )).to eq( '/usr/bin/which' )
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'returns nil for a invalid command if a full path is given' do
|
|
21
|
-
expect(
|
|
21
|
+
expect(klass.new.which( '/usr/bin/which1' )).to eq( nil )
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it 'returns nil if no executable can be found in path' do
|
|
25
|
-
expect(
|
|
25
|
+
expect(klass.new.which('asdfasdf')).to eq( nil )
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it 'uses paths string to search for command' do
|
|
29
|
-
expect(
|
|
29
|
+
expect(klass.new.which('which', paths: '/usr/bin')).to eq('/usr/bin/which')
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it 'uses paths array to search for command' do
|
|
33
|
-
expect(
|
|
33
|
+
expect(klass.new.which('which', paths: ['/usr/bin'])).to eq('/usr/bin/which')
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'uses pathexts to search for command' do
|
|
37
|
-
expect(
|
|
37
|
+
expect(klass.new.which('which', paths: ['/usr/bin'], pathexts: '')).to eq('/usr/bin/which')
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it 'uses pathexts array to search for command' do
|
|
41
|
-
expect(
|
|
41
|
+
expect(klass.new.which( 'which', paths: ['/usr/bin'], pathexts: [''])).to eq('/usr/bin/which')
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
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.3.
|
|
4
|
+
version: 0.3.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:
|
|
12
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|