fluent_command_builder 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,7 +33,15 @@ module FluentCommandBuilder
33
33
 
34
34
  def validate_version
35
35
  validator = VersionValidator.new self.class, @b.path
36
- print yellow, %Q[WARNING: Version validation for command "#{@b.command_name}" failed. Expected version #{validator.version_in_use.to_s(2)} but was #{validator.version_on_path.to_s(2)}.], reset, "\n" unless validator.is_valid?
36
+
37
+ if !validator.can_validate?
38
+ print yellow, %Q[WARNING: Version validation for command "#{@b.command_name}" aborted. An internal error occurred.], reset, "\n"
39
+ return
40
+ end
41
+
42
+ if !validator.is_valid?
43
+ print yellow, %Q[WARNING: Version validation for command "#{@b.command_name}" failed. Expected version #{validator.version_in_use.to_s(2)} but was #{validator.version_on_path.to_s(2)}.], reset, "\n"
44
+ end
37
45
  end
38
46
 
39
47
  end
@@ -1,6 +1,9 @@
1
1
  module FluentCommandBuilder
2
2
  class Version
3
3
 
4
+ VERSION_REGEX = '(?:\d+\.)+(?:\d+)'
5
+ SEQUENCE_SEPARATOR = '.'
6
+
4
7
  attr_accessor :version
5
8
 
6
9
  def initialize(version)
@@ -9,22 +12,33 @@ module FluentCommandBuilder
9
12
  end
10
13
 
11
14
  def compact
12
- @version.match(/^\d+\.\d+/)[0].sub('.', '')
15
+ sequences(2).join
13
16
  end
14
17
 
15
- def to_s(precision=nil)
16
- return @version unless precision
17
- @version.split('.').first(precision).join('.')
18
+ def to_s(count=nil)
19
+ count ? truncate(count) : @version
18
20
  end
19
21
 
20
22
  def self.is_valid?(version)
21
- version.scan(/^(?:\d+\.)+(?:\d+)$/)[0] != nil
23
+ exp = Regexp.new "^#{VERSION_REGEX}$"
24
+ version.scan(exp)[0] != nil
22
25
  end
23
26
 
24
27
  def self.match(value)
25
- version = value.scan(/(?:\d+\.)+(?:\d+)/)[0]
28
+ exp = Regexp.new VERSION_REGEX
29
+ version = value.scan(exp)[0]
26
30
  version ? Version.new(version) : nil
27
31
  end
32
+
33
+ private
34
+
35
+ def sequences(count)
36
+ @version.split(SEQUENCE_SEPARATOR).first(count)
37
+ end
38
+
39
+ def truncate(count)
40
+ sequences(count).join(SEQUENCE_SEPARATOR)
41
+ end
28
42
  end
29
43
 
30
44
  def version_module(command_module)
@@ -9,13 +9,17 @@ module FluentCommandBuilder
9
9
  @path = path
10
10
  end
11
11
 
12
- def is_valid?
13
- version_in_use.compact == version_on_path.compact
12
+ def can_validate?
13
+ begin
14
+ is_valid?
15
+ return true
16
+ rescue
17
+ return false
18
+ end
14
19
  end
15
20
 
16
- def validate
17
- is_valid = version_in_use.compact == version_on_path.compact
18
- puts "WARNING: Command Builder version #{version_in_use} does not match tool version #{version_on_path}." unless is_valid
21
+ def is_valid?
22
+ version_in_use.compact == version_on_path.compact
19
23
  end
20
24
 
21
25
  def version_in_use
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent_command_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70111080000440 !ruby/object:Gem::Requirement
16
+ requirement: &70124100388640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70111080000440
24
+ version_requirements: *70124100388640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: term-ansicolor
27
- requirement: &70111080000000 !ruby/object:Gem::Requirement
27
+ requirement: &70124100388200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70111080000000
35
+ version_requirements: *70124100388200
36
36
  description: Fluent Command Builder makes building command lines easy and intuitive.
37
37
  email: matthew-github@matthewriley.name
38
38
  executables: []