Class: NuGetVersions::NuGetVersion

Inherits:
SemanticVersion show all
Defined in:
lib/nuget_versions/nuget_version.rb

Instance Attribute Summary collapse

Attributes inherited from SemanticVersion

#major, #metadata, #minor, #patch, #release_labels

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SemanticVersion

#!=, #<, #<=, #<=>, #==, #>, #>=, #has_metadata?, #is_prerelease?, #release

Constructor Details

#initialize(major, minor, patch, revision = 0, release_labels = nil, metadata = nil) ⇒ NuGetVersion

Creates a NuGetVersion X.Y.Z, X.Y.Z-alpha, X.Y.Z-alpha+metadata, W.X.Y.Z, W.X.Y.Z-alpha, W.X.Y.Z-alpha+metadata. Parameters:

  • major: W.x.y.z

  • minor: w.X.y.z

  • patch: w.x.Y.z

  • revision: w.x.y.Z

  • release_labels: Prerelease label

  • metadata: Build metadata



21
22
23
24
25
# File 'lib/nuget_versions/nuget_version.rb', line 21

def initialize(major, minor, patch, revision = 0, release_labels = nil,  = nil)
  super(major, minor, patch, release_labels, )

  @revision = Integer(revision, revision.is_a?(String) ? 10 : 0)
end

Instance Attribute Details

#revisionObject

Returns the value of attribute revision.



27
28
29
# File 'lib/nuget_versions/nuget_version.rb', line 27

def revision
  @revision
end

Class Method Details

.copy_of(version) ⇒ Object

Creates a NuGetVersion from an existing NuGetVersion Parameters:

  • version: Version to clone.



6
7
8
9
10
11
# File 'lib/nuget_versions/nuget_version.rb', line 6

def self.copy_of(version)
  revision = 0
  revision = version.revision if version.respond_to? :revision

  return NuGetVersion.new(version.major, version.minor, version.patch, revision, version.release_labels, version.)
end

.parse(value) ⇒ Object



82
83
84
85
86
87
# File 'lib/nuget_versions/nuget_version.rb', line 82

def self.parse(value)
  ver = self.try_parse(value)
  raise "Invalid NuGet version value" if ver.nil?

  ver
end

.try_parse(value) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/nuget_versions/nuget_version.rb', line 89

def self.try_parse(value)
  return nil if value.nil?

  value = value.to_s if !value.is_a? String
  original_value = value

  return nil if value.empty?

  value = value.split("+", 2)

   = (value.length == 2) ? value.last : nil

  value = value.first.split("-", 2)

  return nil if value.empty?

  release_labels = (value.length == 2) ? value.last.split('.') : nil

  parts = value.first.split(".")

  return nil if parts.length < 2 || parts.length > 4
  return nil if release_labels && !SemanticVersion.try_validate_identifiers(release_labels)
  return nil if  && !SemanticVersion.try_validate_identifier()

  begin
    major = Integer(parts[0], 10)
    minor = (parts.length >= 2) ? Integer(parts[1], 10) : 0
    patch = (parts.length >= 3) ? Integer(parts[2], 10) : 0
    revision = (parts.length >= 4) ? Integer(parts[3], 10) : 0
  rescue
    return nil
  end

  ver = NuGetVersion.new(major, minor, patch, revision, release_labels, )
  ver.instance_variable_set("@original_version", original_value)
  ver.instance_variable_set("@original_release", ver.release)

  ver
end

Instance Method Details

#major=(new_value) ⇒ Object



29
30
31
32
# File 'lib/nuget_versions/nuget_version.rb', line 29

def major=(new_value)
  super(new_value)
  @original_version = nil
end

#metadata=(new_value) ⇒ Object



54
55
56
57
# File 'lib/nuget_versions/nuget_version.rb', line 54

def metadata=(new_value)
  super(new_value)
  @original_version = nil
end

#minor=(new_value) ⇒ Object



34
35
36
37
# File 'lib/nuget_versions/nuget_version.rb', line 34

def minor=(new_value)
  super(new_value)
  @original_version = nil
end

#original_versionObject



64
65
66
67
# File 'lib/nuget_versions/nuget_version.rb', line 64

def original_version
  @original_version = nil if !@original_version.nil? && (release != @original_release)
  @original_version
end

#patch=(new_value) ⇒ Object



39
40
41
42
# File 'lib/nuget_versions/nuget_version.rb', line 39

def patch=(new_value)
  super(new_value)
  @original_version = nil
end

#release=(new_value) ⇒ Object



59
60
61
62
# File 'lib/nuget_versions/nuget_version.rb', line 59

def release=(new_value)
  super(new_value)
  @original_version = nil
end

#release_labels=(new_value) ⇒ Object



49
50
51
52
# File 'lib/nuget_versions/nuget_version.rb', line 49

def release_labels=(new_value)
  super(new_value)
  @original_version = nil
end

#to_sObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nuget_versions/nuget_version.rb', line 69

def to_s
  original_version # Test if the release labels array has been mutated

  return @original_version if !@original_version.nil? && !@original_version.empty?

  version = "#{@major}.#{@minor}.#{@patch}"
  version += ".#{@revision}" if revision != 0
  version += "-#{release}" if is_prerelease?
  version += "+#{}" if has_metadata?

  version
end