Class: PivotalIntegration::VersionUpdate::Gradle
- Inherits:
-
Object
- Object
- PivotalIntegration::VersionUpdate::Gradle
- Defined in:
- lib/pivotal-integration/version-update/gradle.rb
Overview
A version updater for dealing with typical Gradle projects. This updater assumes that the version of the current project is stored within a gradle.properties
file in the root of the repository. This properties file should have an entry with a key of version
and version number as the key.
Instance Method Summary collapse
-
#current_version ⇒ String
The current version of the project.
-
#initialize(root) ⇒ Gradle
constructor
Creates an instance of this updater.
-
#supports? ⇒ Boolean
Whether this updater supports updating this project.
-
#update_version(new_version) ⇒ void
Update the version of the project.
Constructor Details
#initialize(root) ⇒ Gradle
Creates an instance of this updater
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pivotal-integration/version-update/gradle.rb', line 27 def initialize(root) @gradle_properties = File. 'gradle.properties', root if File.exist? @gradle_properties groups = nil File.open(@gradle_properties, 'r') do |file| groups = file.read().scan(/version[=:](.*)/) end @version = groups[0] ? groups[0][0]: nil end end |
Instance Method Details
#current_version ⇒ String
The current version of the project
50 51 52 |
# File 'lib/pivotal-integration/version-update/gradle.rb', line 50 def current_version @version end |
#supports? ⇒ Boolean
Whether this updater supports updating this project
43 44 45 |
# File 'lib/pivotal-integration/version-update/gradle.rb', line 43 def supports? !@version.nil? end |
#update_version(new_version) ⇒ void
This method returns an undefined value.
Update the version of the project
58 59 60 61 62 |
# File 'lib/pivotal-integration/version-update/gradle.rb', line 58 def update_version(new_version) contents = File.read(@gradle_properties) contents = contents.gsub(/(version[=:])#{@version}/, "\\1#{new_version}") File.open(@gradle_properties, 'w') { |file| file.write(contents) } end |