Class: App::Version
- Inherits:
-
Object
- Object
- App::Version
- Includes:
- Comparable
- Defined in:
- lib/app_version/app_version.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#build ⇒ Object
Returns the value of attribute build.
-
#build_date ⇒ Object
Returns the value of attribute build_date.
-
#committer ⇒ Object
Returns the value of attribute committer.
-
#format ⇒ Object
Returns the value of attribute format.
-
#major ⇒ Object
Returns the value of attribute major.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#milestone ⇒ Object
Returns the value of attribute milestone.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
Class Method Summary collapse
-
.load(path) ⇒ Object
Loads the version information from a YAML file.
-
.parse(version) ⇒ Object
Parses a version string to create an instance of the Version class.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(args = nil) ⇒ Version
constructor
Creates a new instance of the Version class using information in the passed Hash to construct the version number.
- #to_s ⇒ Object
Constructor Details
#initialize(args = nil) ⇒ Version
Creates a new instance of the Version class using information in the passed Hash to construct the version number.
Version.new(:major => 1, :minor => 0) #=> "1.0"
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/app_version/app_version.rb', line 21 def initialize(args = nil) if args && args.is_a?(Hash) args.keys.reject {|key| key.is_a?(Symbol) }.each {|key| args[key.to_sym] = args.delete(key) } [:major, :minor].each do |param| raise ArgumentError.new("The #{param.to_s} parameter is required") if args[param].blank? end @major = args[:major].to_s @minor = args[:minor].to_s @patch = args[:patch].to_s unless args[:patch].blank? = args[:meta].to_s unless args[:meta].blank? @milestone = args[:milestone].to_s unless args[:milestone].blank? @build = args[:build].to_s unless args[:build].blank? @branch = args[:branch].to_s unless args[:branch].blank? @committer = args[:committer].to_s unless args[:committer].blank? @format = args[:format].to_s unless args[:format].blank? unless args[:build_date].blank? b_date = case args[:build_date] when 'git-revdate' get_revdate_from_git else args[:build_date].to_s end @build_date = Date.parse(b_date) end @build = case args[:build] when 'svn' get_build_from_subversion when 'git-revcount' get_revcount_from_git when 'git-hash' get_hash_from_git when nil, '' nil else args[:build].to_s end end end |
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def branch @branch end |
#build ⇒ Object
Returns the value of attribute build.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def build @build end |
#build_date ⇒ Object
Returns the value of attribute build_date.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def build_date @build_date end |
#committer ⇒ Object
Returns the value of attribute committer.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def committer @committer end |
#format ⇒ Object
Returns the value of attribute format.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def format @format end |
#major ⇒ Object
Returns the value of attribute major.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def major @major end |
#meta ⇒ Object
Returns the value of attribute meta.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def end |
#milestone ⇒ Object
Returns the value of attribute milestone.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def milestone @milestone end |
#minor ⇒ Object
Returns the value of attribute minor.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
9 10 11 |
# File 'lib/app_version/app_version.rb', line 9 def patch @patch end |
Class Method Details
.load(path) ⇒ Object
Loads the version information from a YAML file.
88 89 90 |
# File 'lib/app_version/app_version.rb', line 88 def self.load(path) App::Version.new YAML::load(File.open(path)) end |
.parse(version) ⇒ Object
Parses a version string to create an instance of the Version class.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/app_version/app_version.rb', line 65 def self.parse(version) m = version.match(/(\d+)\.(\d+)(?:\.(\d+))?(?:-([\w.\d]+))?(?:\sM(\d+))?(?:\s\((\d+)\))?(?:\sof\s(\w+))?(?:\sby\s(\w+))?(?:\son\s(\S+))?/) raise ArgumentError.new("The version '#{version}' is unparsable") if m.nil? version = App::Version.new :major => m[1], :minor => m[2], :patch => m[3], :meta => m[4], :milestone => m[5], :build => m[6], :branch => m[7], :committer => m[8] if (m[9] && m[9] != '') date = Date.parse(m[9]) version.build_date = date end return version end |
Instance Method Details
#<=>(other) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/app_version/app_version.rb', line 92 def <=>(other) # if !self.build.nil? && !other.build.nil? # return self.build <=> other.build # end %w(build major minor patch milestone branch meta committer build_date).each do |meth| rhs = self.send(meth) || -1 lhs = other.send(meth) || -1 ret = lhs <=> rhs return ret unless ret == 0 end return 0 end |
#to_s ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/app_version/app_version.rb', line 108 def to_s if @format str = eval(@format.to_s.inspect) else str = "#{major}.#{minor}" str << ".#{patch}" unless patch.blank? str << "-#{meta}" unless .blank? str << " M#{milestone}" unless milestone.blank? str << " (#{build})" unless build.blank? str << " of #{branch}" unless branch.blank? str << " by #{committer}" unless committer.blank? str << " on #{build_date}" unless build_date.blank? end str end |