Class: Raykit::ConanPackage

Inherits:
Object
  • Object
show all
Defined in:
lib/raykit/conanpackage.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ ConanPackage

Returns a new instance of ConanPackage.



7
8
9
10
# File 'lib/raykit/conanpackage.rb', line 7

def initialize(name, version)
  @name = name
  @version = version
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/raykit/conanpackage.rb', line 5

def name
  @name
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/raykit/conanpackage.rb', line 5

def version
  @version
end

Class Method Details

.get_version(text, name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/raykit/conanpackage.rb', line 12

def self.get_version(text, name)
  # "gtest/0.0.14@my+channel.com/branch"
  # gtest/1.10.0
  [/\b#{name}\/([\d\.]+)/].each { |regex|
    matches = text.scan(regex)
    if matches.length > 0 && matches[0].length > 0
      return matches[0][0]
    end
  }
  ""
end

.set_version(text, name, version) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/raykit/conanpackage.rb', line 24

def self.set_version(text, name, version)
  #puts "ConanPackage::set_version"
  new_text = text
  [/(\b#{name}\/[\d\.]+)/].each { |regex|
    matches = text.scan(regex)
    if matches.length > 0 && matches[0].length > 0
      orig = matches[0][0]
      oversion = get_version(orig, name)
      mod = orig.sub(oversion, version)
      #puts "match[0][0] " + matches[0][0]
      #puts "old version " + oversion
      #puts "new version " + version
      #puts "updating from #{orig} to #{mod}"
      new_text = new_text.gsub(orig, mod)
    end
  }
  new_text
end

.set_version_in_file(filename, name, version) ⇒ Object



43
44
45
46
47
# File 'lib/raykit/conanpackage.rb', line 43

def self.set_version_in_file(filename, name, version)
  text = set_version(IO.read(filename), name, version)
  orig = IO.read(filename)
  File.open(filename, "w") { |f| f.puts text } if (text != orig)
end