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, #server_url, #site_id, #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.



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

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parent_project_idObject (readonly)

Returns the value of attribute parent_project_id.



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

def parent_project_id
  @parent_project_id
end

Class Method Details

.from_collection_response(client, path, xml) ⇒ Object



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

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



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

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



74
75
76
# File 'lib/tableau_server_client/resources/project.rb', line 74

def extract_value_in_description(key)
  extract_values_in_description[key]
end

#extract_values_in_descriptionObject



69
70
71
72
# File 'lib/tableau_server_client/resources/project.rb', line 69

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



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

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

#parent_projectsObject



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

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



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

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

#reloadObject



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

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

#root_projectObject



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

def root_project
  parent_projects[0] || self
end

#root_project?Boolean

Returns:

  • (Boolean)


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

def root_project?
  self.parent_project_id.nil?
end

#workbooksObject



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

def workbooks
  @client.get_collection(Workbook.location(site_path, filter: [])).select {|w|
    w.project_id == id
  }
end