getversion 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module GetVersion
7
7
  end
8
8
 
9
9
  executable 'xcodebuild' do
10
- find_version_in_output @exe, '-version'
10
+ find_version_in_output path, '-version'
11
11
  end
12
12
 
13
13
  end
@@ -5,11 +5,11 @@ module GetVersion
5
5
  namespace :google
6
6
 
7
7
  executable 'appcfg.py' do
8
- google_appengine_version @exe
8
+ google_appengine_version
9
9
  end
10
10
 
11
11
  executable 'dev_appserver.py' do
12
- google_appengine_version @exe
12
+ google_appengine_version
13
13
  end
14
14
 
15
15
  end
@@ -3,7 +3,7 @@ module GetVersion
3
3
  namespace :jetbrains
4
4
 
5
5
  executable 'dotcover' do
6
- find_version_in_output @exe
6
+ find_version_in_output
7
7
  end
8
8
 
9
9
  end
@@ -7,19 +7,19 @@ module GetVersion
7
7
  end
8
8
 
9
9
  executable 'installutil' do
10
- find_version_in_output @exe
10
+ find_version_in_output
11
11
  end
12
12
 
13
13
  executable 'msbuild' do
14
- find_version_in_output @exe, '/version'
14
+ find_version_in_output '/version'
15
15
  end
16
16
 
17
17
  executable 'msdeploy' do
18
- find_version_in_output @exe
18
+ find_version_in_output
19
19
  end
20
20
 
21
21
  executable 'mstest' do
22
- find_version_in_output @exe, '/help'
22
+ find_version_in_output '/help'
23
23
  end
24
24
 
25
25
  executable 'netsh' do
@@ -27,11 +27,11 @@ module GetVersion
27
27
  end
28
28
 
29
29
  executable 'nuget' do
30
- find_version_in_output @exe
30
+ find_version_in_output
31
31
  end
32
32
 
33
33
  executable 'tf' do
34
- find_version_in_output @exe
34
+ find_version_in_output
35
35
  end
36
36
 
37
37
  end
@@ -3,15 +3,15 @@ module GetVersion
3
3
  namespace :rubygems
4
4
 
5
5
  executable 'bundle' do
6
- find_version_in_output @exe, '--version'
6
+ find_version_in_output '--version'
7
7
  end
8
8
 
9
9
  executable 'cucumber' do
10
- find_version_in_output @exe, '--version'
10
+ find_version_in_output '--version'
11
11
  end
12
12
 
13
13
  executable 'rake' do
14
- find_version_in_output @exe, '--version'
14
+ find_version_in_output '--version'
15
15
  end
16
16
 
17
17
  end
@@ -1,19 +1,19 @@
1
1
  module GetVersion
2
2
 
3
3
  executable 'conlinkchecker' do
4
- find_version_in_output @exe
4
+ find_version_in_output
5
5
  end
6
6
 
7
7
  executable 'nunit' do
8
- find_version_in_output @exe, '/help'
8
+ find_version_in_output '/help'
9
9
  end
10
10
 
11
11
  executable '7z' do
12
- find_version_in_output @exe
12
+ find_version_in_output
13
13
  end
14
14
 
15
15
  executable '7za' do
16
- find_version_in_output @exe
16
+ find_version_in_output
17
17
  end
18
18
 
19
19
  end
@@ -0,0 +1,29 @@
1
+ require_relative 'execution_context'
2
+ require_relative 'path_finder'
3
+ require_relative 'path'
4
+
5
+ module GetVersion
6
+ class Executable
7
+
8
+ attr_reader :name, :namespace, :block
9
+
10
+ def initialize(name, namespace, &block)
11
+ @name = name
12
+ @namespace = namespace
13
+ @block = block
14
+ end
15
+
16
+ def version
17
+ c = ExecutionContext.new path
18
+ c.execute &@block
19
+ end
20
+
21
+ def path
22
+ dir = PathFinder.find_path @name
23
+ exclusions = %w(.)
24
+ exclusions.include?(dir) ? nil : dir
25
+ dir ? Path.new(dir, name).evaluated_path : @name
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'version'
2
+
3
+ module GetVersion
4
+ class ExecutionContext
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ end
9
+
10
+ def execute(&block)
11
+ instance_eval &block
12
+ end
13
+
14
+ def path
15
+ @path
16
+ end
17
+
18
+ def find_version_in_output(arg=nil)
19
+ ExecutionContext.find_version_in_output @path, arg
20
+ end
21
+
22
+ def self.find_version_in_output(path, arg=nil)
23
+ output = `"#{path}" #{arg} 2>&1`
24
+ v = Version.match output
25
+ v ? v.version : nil
26
+ end
27
+
28
+ def google_appengine_version(path=@path)
29
+ path = File.dirname path
30
+ version_file = File.join path, 'VERSION'
31
+ YAML::load_file(version_file)['release']
32
+ end
33
+
34
+ def osx_version
35
+ ExecutionContext.find_version_in_output 'sw_vers', '-productVersion'
36
+ end
37
+
38
+ def windows_version
39
+ find_version_in_output 'ver'
40
+ end
41
+
42
+ end
43
+ end
data/lib/getversion.rb CHANGED
@@ -1,28 +1,36 @@
1
- require_relative 'getversion/path_finder'
2
- require_relative 'getversion/path'
3
- require_relative 'getversion/helpers'
1
+ require_relative 'getversion/executable'
4
2
 
5
3
  module GetVersion
6
4
 
7
5
  @executables = []
8
6
 
9
7
  def self.[](name)
10
- executable = @executables.find { |e| e[:name] == name }
11
- path = PathFinder.find_path name
12
- path = nil if path == '.'
13
- @exe = path ? Path.new(path, name).evaluated_path : name
14
- instance_eval &executable[:block]
8
+ executable = find_executable(name) || executable_for_guessing(name)
9
+ executable.version
15
10
  end
16
11
 
17
12
  private
18
13
 
14
+ def self.executable_for_guessing(name)
15
+ Executable.new name, nil do
16
+ args = %w(--version -version /version version --help -help /help help) << nil
17
+ versions = args.map { |arg| find_version_in_output arg }.compact.uniq
18
+ versions[0] if versions.length == 1
19
+ end
20
+ end
21
+
22
+ def self.find_executable(name)
23
+ @executables.find { |e| e.name == name }
24
+ end
25
+
19
26
  def self.namespace(namespace)
20
27
  @namespace = namespace
21
28
  yield if block_given?
22
29
  end
23
30
 
24
31
  def self.executable(name, &block)
25
- @executables << {name: name, namespace: @namespace, block: block}
32
+ executable = Executable.new name, @namespace, &block
33
+ @executables << executable
26
34
  end
27
35
 
28
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -25,7 +25,8 @@ files:
25
25
  - lib/getversion/detectors/rubygems.rb
26
26
  - lib/getversion/detectors/uncategorised.rb
27
27
  - lib/getversion/detectors.rb
28
- - lib/getversion/helpers.rb
28
+ - lib/getversion/executable.rb
29
+ - lib/getversion/execution_context.rb
29
30
  - lib/getversion/path.rb
30
31
  - lib/getversion/path_finder.rb
31
32
  - lib/getversion/path_finders/unix_path_finder.rb
@@ -1,25 +0,0 @@
1
- require_relative 'version'
2
-
3
- module GetVersion
4
-
5
- def self.find_version_in_output(executable, args=nil)
6
- output = `"#{executable}" #{args} 2>&1`
7
- v = Version.match output
8
- v ? v.version : nil
9
- end
10
-
11
- def self.google_appengine_version(executable)
12
- path = File.dirname executable
13
- version_file = File.join path, 'VERSION'
14
- YAML::load_file(version_file)['release']
15
- end
16
-
17
- def self.osx_version
18
- find_version_in_output 'sw_vers', '-productVersion'
19
- end
20
-
21
- def self.windows_version
22
- find_version_in_output 'ver'
23
- end
24
-
25
- end