Class: AlpacaBuildTool::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/alpacabuildtool/entities/project.rb

Overview

VisualStudioProject provides project representation and methods to modify it's AssemblyVersion.cs file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, dir) ⇒ Project

Creates instance of class

line

line from .sln file with project information

dir

solution directory

s = AlpacaBuildTool::VisualStudioProject.new(
  'Project("{FAE04EC0...5254043711}"'
  'd:\')
  # => #<**:VisualStudioProject:** @file="d:/sln1/some.csproj" **>

18
19
20
21
22
23
24
# File 'lib/alpacabuildtool/entities/project.rb', line 18

def initialize(line, dir)
  items = line.gsub(/".*?"/).to_a
  _, @name, file, _ = items.map { |item| item.to_s.gsub('"', '') }
  dir = File.expand_path(dir)
  @dir = File.dirname(File.join(dir, file))
  @file = File.join(dir, file)
end

Instance Attribute Details

#dirObject

Returns the value of attribute dir


6
7
8
# File 'lib/alpacabuildtool/entities/project.rb', line 6

def dir
  @dir
end

#fileObject

Returns the value of attribute file


6
7
8
# File 'lib/alpacabuildtool/entities/project.rb', line 6

def file
  @file
end

#nameObject

Returns the value of attribute name


6
7
8
# File 'lib/alpacabuildtool/entities/project.rb', line 6

def name
  @name
end

Instance Method Details

#to_sObject

Overrides to_s method to provide nice convertion to string


28
29
30
# File 'lib/alpacabuildtool/entities/project.rb', line 28

def to_s
  "{#{@name};#{@file}}"
end

#update_version(new_version) ⇒ Object

Updates AssemblyInfo.cs file under the project with new_version

new_version

version that need to be used as assembly version

and assembly file version


37
38
39
40
41
42
43
# File 'lib/alpacabuildtool/entities/project.rb', line 37

def update_version(new_version)
  info_file = File.join(@dir, 'Properties', 'AssemblyInfo.cs')
  content = IO.readlines(info_file)
  open(info_file, 'w') do |io|
    content.each { |line| io.write replace_version(line, new_version) }
  end
end