Class: TeamcityRuby::VcsRoot

Inherits:
Object
  • Object
show all
Extended by:
Resource
Defined in:
lib/teamcity_ruby/vcs_root.rb

Constant Summary collapse

VCS_TYPES =
{ :git => 'jetbrains.git', :svn => 'svn' }
DEFAULT_PROJECT =
"_Root"
DEFAULT_VCS_TYPE =
"jetbrains.git"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

all, client, extended, find, locator, resource_name, url_path

Constructor Details

#initialize(options = {}) ⇒ VcsRoot

Returns a new instance of VcsRoot.



36
37
38
39
40
41
# File 'lib/teamcity_ruby/vcs_root.rb', line 36

def initialize(options = {})
  @teamcity_id = options["id"]
  @name = options["name"]
  @vcs_type = options["vcsName"]
  @properties = flat_properties(options["properties"]) if options["properties"]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/teamcity_ruby/vcs_root.rb', line 10

def name
  @name
end

#parent_idObject (readonly)

Returns the value of attribute parent_id.



10
11
12
# File 'lib/teamcity_ruby/vcs_root.rb', line 10

def parent_id
  @parent_id
end

#propertiesObject (readonly)

Returns the value of attribute properties.



10
11
12
# File 'lib/teamcity_ruby/vcs_root.rb', line 10

def properties
  @properties
end

#teamcity_idObject (readonly)

Returns the value of attribute teamcity_id.



10
11
12
# File 'lib/teamcity_ruby/vcs_root.rb', line 10

def teamcity_id
  @teamcity_id
end

#vcs_typeObject (readonly)

Returns the value of attribute vcs_type.



10
11
12
# File 'lib/teamcity_ruby/vcs_root.rb', line 10

def vcs_type
  @vcs_type
end

Class Method Details

.create(options = {}, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/teamcity_ruby/vcs_root.rb', line 15

def self.create(options = {}, &block)
  vcs_type = if options[:vcs_type]
    VCS_TYPES[options[:vcs_type]] || options[:vcs_type]
  else
    DEFAULT_VCS_TYPE
  end

  project_id = options.fetch(:project_id) { DEFAULT_PROJECT }

  attributes = {
    "name" => options[:name],
    "vcsName" => vcs_type,
    "projectLocator" => "id:#{project_id}"
  }

  builder = TeamCity::ElementBuilder.new(attributes, &block)

  response = client.post("/vcs-roots", :body => builder.to_request_body)
  VcsRoot.find(:id => response["id"])
end

Instance Method Details

#destroy!Object



43
44
45
# File 'lib/teamcity_ruby/vcs_root.rb', line 43

def destroy!
  client.delete("/vcs-roots/id:#{self.teamcity_id}")
end

#flat_properties(properties) ⇒ Object



47
48
49
50
51
# File 'lib/teamcity_ruby/vcs_root.rb', line 47

def flat_properties(properties)
  properties.delete("property").map do |p|
    { p["name"] => p["value"] }
  end
end