Class: TableauServerClient::Resources::Project

Inherits:
Resource
  • Object
show all
Defined in:
lib/tableau_server_client/resources/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

attr_reader, attributes, #attributes, #delete!, extract_attributes, extract_site_path, #initialize, location, #location, #path, plural_resource_name, resource_name, #site_path

Methods included from TableauServerClient::RequestBuilder

#build_request

Constructor Details

This class inherits a constructor from TableauServerClient::Resources::Resource

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/tableau_server_client/resources/project.rb', line 8

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/tableau_server_client/resources/project.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/tableau_server_client/resources/project.rb', line 8

def name
  @name
end

#parent_project_idObject (readonly)

Returns the value of attribute parent_project_id.



8
9
10
# File 'lib/tableau_server_client/resources/project.rb', line 8

def parent_project_id
  @parent_project_id
end

Class Method Details

.from_collection_response(client, path, xml) ⇒ Object



15
16
17
18
19
20
# File 'lib/tableau_server_client/resources/project.rb', line 15

def self.from_collection_response(client, path, xml)
  xml.xpath("//xmlns:projects/xmlns:project").each do |s|
    id = s['id']
    yield from_response(client, "#{path}/#{id}", s)
  end
end

.from_response(client, path, xml) ⇒ Object



10
11
12
13
# File 'lib/tableau_server_client/resources/project.rb', line 10

def self.from_response(client, path, xml)
  attrs = extract_attributes(xml)
  new(client, path, attrs)
end

Instance Method Details

#extract_value_in_description(key) ⇒ Object



67
68
69
# File 'lib/tableau_server_client/resources/project.rb', line 67

def extract_value_in_description(key)
  extract_values_in_description[key]
end

#extract_values_in_descriptionObject



62
63
64
65
# File 'lib/tableau_server_client/resources/project.rb', line 62

def extract_values_in_description
  @values_in_description ||=\
    description.lines.map { |l|/^(.*):\s*(.*)$/.match(l) }.reject { |m| m.nil? }.map { |m| m[1,2] }.to_h
end

#hierarchyObject



58
59
60
# File 'lib/tableau_server_client/resources/project.rb', line 58

def hierarchy
  (parent_projects << self).map {|p| p.name }.join('/')
end

#parent_projectsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tableau_server_client/resources/project.rb', line 41

def parent_projects
  return @parent_projects if @parent_projects
  @parent_projects = []
  curr_pj = self
  pjs = @client.get_collection Project.location(site_path)
  while ! curr_pj.root_project?
    pjs.each do |pj|
      if pj.id == curr_pj.parent_project_id
        @parent_projects.unshift pj
        curr_pj = pj
        break
      end
    end
  end
  return @parent_projects
end

#redshift_usernameObject



27
28
29
30
31
# File 'lib/tableau_server_client/resources/project.rb', line 27

def redshift_username
  if md = description.match(/^REDSHIFT_USERNAME: (.+)$/)
    return md[1]
  end
end

#reloadObject



22
23
24
25
# File 'lib/tableau_server_client/resources/project.rb', line 22

def reload
  prjs = @client.get_collection Project.location(site_path, filter: ["name:eq:#{name}"])
  prjs.select {|p| p.id == id }.first
end

#root_projectObject



37
38
39
# File 'lib/tableau_server_client/resources/project.rb', line 37

def root_project
  parent_projects[0] || self
end

#root_project?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/tableau_server_client/resources/project.rb', line 33

def root_project?
  self.parent_project_id.nil?
end