Class: Raykit::NuGetPackage
- Inherits:
-
Object
- Object
- Raykit::NuGetPackage
- Defined in:
- lib/raykit/nugetpackage.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .get(text, name) ⇒ Object
- .get_version(text, name) ⇒ Object
- .set_version(text, name, version) ⇒ Object
- .set_version_in_file(filename, name, version) ⇒ Object
Instance Method Summary collapse
-
#initialize(name, version) ⇒ NuGetPackage
constructor
A new instance of NuGetPackage.
Constructor Details
#initialize(name, version) ⇒ NuGetPackage
Returns a new instance of NuGetPackage.
7 8 9 10 |
# File 'lib/raykit/nugetpackage.rb', line 7 def initialize(name, version) @name = name @version = version end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/raykit/nugetpackage.rb', line 5 def name @name end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/raykit/nugetpackage.rb', line 5 def version @version end |
Class Method Details
.get(text, name) ⇒ Object
12 13 14 |
# File 'lib/raykit/nugetpackage.rb', line 12 def self.get(text, name) Raykit::NugetPackage.new(name, get_version(text, name)) end |
.get_version(text, name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/raykit/nugetpackage.rb', line 16 def self.get_version(text, name) [/<PackageReference[\s]+Include=\"#{name}\"[\s]+Version=\"([\d\.]+)/, /<Reference[\s]+Include=\"#{name},[\s]+Version=([\d\.]+)/, /<HintPath>[\.\\\/\w\d]+#{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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/raykit/nugetpackage.rb', line 28 def self.set_version(text, name, version) puts "NuGetPackage::set_version" new_text = text [/(<PackageReference[\s]+Include=\"#{name}\"[\s]+Version=\"[\d\.]+)/, /(<Reference[\s]+Include=\"#{name},[\s]+Version=[\d\.]+)/, /(<HintPath>[\.\\\/\w\d]+#{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 new_text = new_text.gsub(orig, mod) end } new_text end |
.set_version_in_file(filename, name, version) ⇒ Object
48 49 50 51 52 |
# File 'lib/raykit/nugetpackage.rb', line 48 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 |