Class: Raykit::Version
- Inherits:
-
Object
- Object
- Raykit::Version
- Defined in:
- lib/raykit/version.rb
Overview
Version functionality
Instance Attribute Summary collapse
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Class Method Summary collapse
-
.bump(version) ⇒ Object
increment to last digit of a version string.
- .bump_file(filename) ⇒ Object
-
.detect(name, verbose = false) ⇒ Object
detect a version number based on the NAME variable, if defined.
- .detect_from_file(filename, regex, verbose) ⇒ Object
- .set_version_in_file(filename, version) ⇒ Object
- .sync_file_versions(source_filename, destination_filename) ⇒ Object
Instance Attribute Details
#start_time ⇒ Object
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/raykit/version.rb', line 8 def start_time @start_time end |
Class Method Details
.bump(version) ⇒ Object
increment to last digit of a version string
70 71 72 73 74 75 |
# File 'lib/raykit/version.rb', line 70 def self.bump(version) # major.minor[.build[.revision]] (example: 1.2.12.102) version_ints = version.split(".").map(&:to_i) version_ints[-1] = version_ints.last + 1 version_ints.map(&:to_s).join(".") end |
.bump_file(filename) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/raykit/version.rb', line 77 def self.bump_file(filename) warn "Raykit::Version.bump_file filename '#{filename}' does not exist." unless File.exist?(filename) old_version = "" if filename.include?(".gemspec") old_version = detect_from_file(filename, /version\s?=\s?['|"]([.\d]+)['|"]/, false) end old_version = detect_from_file(filename, /<Version>([-\w\d.]+)</, false) if filename.include?(".csproj") if old_version.length.positive? new_version = bump(old_version) set_version_in_file(filename, new_version) end new_version end |
.detect(name, verbose = false) ⇒ Object
detect a version number based on the NAME variable, if defined
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/raykit/version.rb', line 11 def self.detect(name, verbose = false) version = detect_from_file("#{name}/#{name}.csproj", /<Version>([-\w\d.]+)</, verbose) return version if version.length.positive? version = detect_from_file("#{name}/Properties/AssemblyInfo.cs", /^\[assembly: AssemblyVersion\("([.\w]+)/, verbose) return version if version.length.positive? version = detect_from_file("#{name}.gemspec", /version\s+=\s+['"]([\w.]+)['"]/, verbose) return version if version.length.positive? version = detect_from_file("#{name}.gemspec", /version\s?=\s?['|"]([.\d]+)['|"]/, verbose) return version if version.length.positive? version = detect_from_file("#{name}.nuspec", /<[Vv]ersion>([\d.]+)</, verbose) return version if version.length.positive? if verbose warning = "\u26A0" symbol = Rainbow(warning.encode("utf-8")).yellow puts "#{symbol} version not detected" end "" end |
.detect_from_file(filename, regex, verbose) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/raykit/version.rb', line 36 def self.detect_from_file(filename, regex, verbose) version = "" if File.exist?(filename) match = IO.read(filename).match(regex) version = match.captures[0] if !match.nil? && match.captures.length.positive? else return "" end if verbose if version.length.positive? puts "version detected in #{filename}" else puts "no version detected in #{filename}, regex #{regex.source}" end end version end |
.set_version_in_file(filename, version) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/raykit/version.rb', line 54 def self.set_version_in_file(filename, version) text = IO.read(filename) new_text = text.gsub(/version\s?=\s?['|"]([.\d]+)['|"]/, "version='#{version}'") if filename.include?(".gemspec") new_text = text.gsub(/<Version>([-\w\d.]+)</, "<Version>#{version}<") if filename.include?(".csproj") # new_text=text.gsub(/<Version>([-\w\d.]+)</,"<Version>#{version}<") # new_text=new_text.gsub(/version[\s]+=\s?['|"]([.\d]+)['|"]/,"version='#{version}'") # new_text=new_text.gsub(/Version="([.\d]+)"/,"Version=\"#{version}\"") File.open(filename, "w") { |f| f.write(new_text) } if new_text != text end |
.sync_file_versions(source_filename, destination_filename) ⇒ Object
64 65 66 67 |
# File 'lib/raykit/version.rb', line 64 def self.sync_file_versions(source_filename, destination_filename) version = Version.detect_from_file(source_filename, /<Version>([-\w\d.]+)</, false) Version.set_version_in_file(destination_filename, version) end |