Class: CMake::Base
- Inherits:
-
Object
- Object
- CMake::Base
- Defined in:
- lib/vcpkg_pipeline/extension/cmake_vpl.rb
Overview
CMake::Base
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_path ⇒ Object
Returns the value of attribute content_path.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#project ⇒ Object
Returns the value of attribute project.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(path) ⇒ Base
constructor
A new instance of Base.
- #parse_content(content) ⇒ Object
- #parse_project(piece) ⇒ Object
- #parse_project_name(clean_project) ⇒ Object
- #parse_project_version(clean_project) ⇒ Object
- #to_s ⇒ Object
- #version_increased ⇒ Object
- #version_update(new_version = nil) ⇒ Object
Constructor Details
#initialize(path) ⇒ Base
Returns a new instance of Base.
18 19 20 21 22 23 24 25 26 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 18 def initialize(path) @path = path @content_path = "#{path}/CMakeLists.txt" VPL.error("#{@content_path} Not Found") unless File.exist? @content_path @content = File.read(@content_path) parse_content(@content) end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
16 17 18 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 16 def content @content end |
#content_path ⇒ Object
Returns the value of attribute content_path.
16 17 18 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 16 def content_path @content_path end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 16 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
16 17 18 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 16 def path @path end |
#project ⇒ Object
Returns the value of attribute project.
16 17 18 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 16 def project @project end |
#version ⇒ Object
Returns the value of attribute version.
16 17 18 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 16 def version @version end |
Instance Method Details
#parse_content(content) ⇒ Object
28 29 30 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 28 def parse_content(content) content.each_line(')') { |piece| parse_project(piece) } end |
#parse_project(piece) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 32 def parse_project(piece) return unless piece.include? 'project' @project = piece clean_project = piece.clean parse_project_name(clean_project) parse_project_version(clean_project) end |
#parse_project_name(clean_project) ⇒ Object
42 43 44 45 46 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 42 def parse_project_name(clean_project) regex_name = /project \( ([^ ]*) / regex_name.match(clean_project) @name = Regexp.last_match(1) end |
#parse_project_version(clean_project) ⇒ Object
48 49 50 51 52 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 48 def parse_project_version(clean_project) regex_version = /VERSION ([^ ]*) / regex_version.match(clean_project) @version = Regexp.last_match(1) end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 74 def to_s "#{name}-#{version}" end |
#version_increased ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 54 def version_increased regex_version = /([^.]*)\.([^.]*)\.([^.]*)\.*([^.]*)/ regex_version.match(@version) new_patch = Regexp.last_match(3).to_i + 1 "#{Regexp.last_match(1)}.#{Regexp.last_match(2)}.#{new_patch}#{Regexp.last_match(4)}" end |
#version_update(new_version = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vcpkg_pipeline/extension/cmake_vpl.rb', line 62 def version_update(new_version = nil) new_version ||= version_increased new_project = @project.sub(@version, new_version) new_content = @content.sub(@project, new_project) File.write(@content_path, new_content) @content = new_content @project = new_project @version = new_version end |