Class: TableauServerClient::Resources::Resource
Direct Known Subclasses
Connection, Datasource, ExtractRefresh, Group, Job, Project, Schedule, Site, Subscription, User, View, Workbook
Defined Under Namespace
Classes: Attribute, Location
Class Method Summary
collapse
Instance Method Summary
collapse
#build_request
Constructor Details
#initialize(client, path, attributes) ⇒ Resource
Returns a new instance of Resource.
7
8
9
10
11
|
# File 'lib/tableau_server_client/resources/resource.rb', line 7
def initialize(client, path, attributes)
@client = client
@path = path
attributes.each {|k,v| instance_variable_set("@#{k}",v) }
end
|
Class Method Details
.attr_reader(*vars) ⇒ Object
13
14
15
16
17
|
# File 'lib/tableau_server_client/resources/resource.rb', line 13
def self.attr_reader(*vars)
@attributes ||= []
@attributes.concat (vars.map { |v| Attribute.new(v.to_s) })
super(*vars)
end
|
.attributes ⇒ Object
19
20
21
|
# File 'lib/tableau_server_client/resources/resource.rb', line 19
def self.attributes
@attributes
end
|
36
37
38
39
40
41
|
# File 'lib/tableau_server_client/resources/resource.rb', line 36
def self.(xml)
unless xml.name == resource_name
raise "Element name (#{xml.name}) does not match with resource name (#{resource_name})"
end
attributes.select {|a| xml.key?(a.camelCase) }.map {|a| [a.to_sym, xml[a.camelCase]] }.to_h
end
|
43
44
45
46
|
# File 'lib/tableau_server_client/resources/resource.rb', line 43
def self.(path)
p = path.split('/')
p.slice(p.index('sites'),2).join('/')
end
|
.location(prefix, id = nil, filter: []) ⇒ Object
31
32
33
34
|
# File 'lib/tableau_server_client/resources/resource.rb', line 31
def self.location(prefix, id=nil, filter: [])
path = [prefix, plural_resource_name, id].compact.join("/")
Location.new(self, path, filter.empty? ? {} : {filter: filter.join(',')})
end
|
.plural_resource_name ⇒ Object
27
28
29
|
# File 'lib/tableau_server_client/resources/resource.rb', line 27
def self.plural_resource_name
"#{self.resource_name}s"
end
|
.resource_name ⇒ Object
23
24
25
|
# File 'lib/tableau_server_client/resources/resource.rb', line 23
def self.resource_name
self.name.split("::").last.sub(/./){ $&.downcase }
end
|
Instance Method Details
#attributes ⇒ Object
48
49
50
|
# File 'lib/tableau_server_client/resources/resource.rb', line 48
def attributes
self.class.attributes
end
|
#delete! ⇒ Object
72
73
74
|
# File 'lib/tableau_server_client/resources/resource.rb', line 72
def delete!
@client.delete self
end
|
#location(query_params: {}) ⇒ Object
56
57
58
|
# File 'lib/tableau_server_client/resources/resource.rb', line 56
def location(query_params: {})
Location.new(self, path, query_params)
end
|
#path ⇒ Object
52
53
54
|
# File 'lib/tableau_server_client/resources/resource.rb', line 52
def path
@path
end
|
#server_url ⇒ Object
68
69
70
|
# File 'lib/tableau_server_client/resources/resource.rb', line 68
def server_url
@client.server_url
end
|
#site_id ⇒ Object
64
65
66
|
# File 'lib/tableau_server_client/resources/resource.rb', line 64
def site_id
site_path.split('/')[1]
end
|
#site_path ⇒ Object
60
61
62
|
# File 'lib/tableau_server_client/resources/resource.rb', line 60
def site_path
self.class.(path)
end
|