Class: Chef::Cookbook::Metadata::Version
- Inherits:
-
Object
- Object
- Chef::Cookbook::Metadata::Version
- Includes:
- Comparable
- Defined in:
- lib/chef/cookbook/metadata/version.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
Instance Method Summary collapse
- #<=>(v) ⇒ Object
- #_parse(str = "") ⇒ Object
-
#initialize(str = "") ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(str = "") ⇒ Version
Returns a new instance of Version.
30 31 32 |
# File 'lib/chef/cookbook/metadata/version.rb', line 30 def initialize(str="") @major, @minor, @patch = _parse(str) end |
Instance Attribute Details
#major ⇒ Object
Returns the value of attribute major.
26 27 28 |
# File 'lib/chef/cookbook/metadata/version.rb', line 26 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
26 27 28 |
# File 'lib/chef/cookbook/metadata/version.rb', line 26 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
26 27 28 |
# File 'lib/chef/cookbook/metadata/version.rb', line 26 def patch @patch end |
Instance Method Details
#<=>(v) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/chef/cookbook/metadata/version.rb', line 53 def <=>(v) major, minor, patch = ( [ :major, :minor, :patch ].collect do |method| self.send(method) <=> v.send(method) end ) Chef::Log.debug "(#{self.to_s}/#{v.to_s}) major,minor,patch: #{[major,minor,patch].join(',')}" # all these returns feels like C, surely there is a better way! if major == 0 && minor == 0 && patch == 0 comp = 0 end if major == 1 comp = 1 end if major == 0 && minor == 1 && patch == -1 comp = 1 end if minor == 1 && major == 0 && patch == 0 comp = 1 end if patch == 1 && major == 0 && minor == 0 comp = 1 end return (comp || -1) end |
#_parse(str = "") ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/cookbook/metadata/version.rb', line 34 def _parse(str="") @major, @minor, @patch = case str.to_s when /^(\d+)\.(\d+)\.(\d+)$/ [ $1.to_i, $2.to_i, $3.to_i ] when /^(\d+)\.(\d+)$/ [ $1.to_i, $2.to_i, 0 ] else raise "Metadata version '#{str.to_s}' does not match 'x.y.z' or 'x.y'" end end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/chef/cookbook/metadata/version.rb', line 45 def inspect "#{@major}.#{@minor}.#{@patch}" end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/chef/cookbook/metadata/version.rb', line 49 def to_s "#{@major}.#{@minor}.#{@patch}" end |