Class: ActiveSP::Site

Inherits:
Base
  • Object
show all
Extended by:
Caching, PersistentCaching
Includes:
Util
Defined in:
lib/activesp/site.rb

Defined Under Namespace

Classes: Service

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Caching

extended

Methods inherited from Base

#attribute, #attribute_type, #attribute_types, #attributes, #has_attribute?, #has_writable_attribute?, #method_missing, #reload, #set_attribute

Constructor Details

#initialize(connection, url, depth = 0) ⇒ Site

Returns a new instance of Site.



42
43
44
45
# File 'lib/activesp/site.rb', line 42

def initialize(connection, url, depth = 0)
  @connection, @url, @depth = connection, url, depth
  @services = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveSP::Base

Instance Attribute Details

#connectionObject (readonly)



38
39
40
# File 'lib/activesp/site.rb', line 38

def connection
  @connection
end

#urlString (readonly)

The URL of this site

Returns:

  • (String)


36
37
38
# File 'lib/activesp/site.rb', line 36

def url
  @url
end

Instance Method Details

#/(name) ⇒ Site, List

Returns the site or list with the given name, or nil if it does not exist

Parameters:

  • name (String)

    The name of the site or list

Returns:



129
130
131
# File 'lib/activesp/site.rb', line 129

def /(name)
  list(name) || site(name)
end

#accessible?Boolean

Returns:

  • (Boolean)


189
190
191
192
193
194
# File 'lib/activesp/site.rb', line 189

def accessible?
  data
  true
rescue Savon::HTTPError
  false
end

#content_type(id) ⇒ Object



145
146
147
# File 'lib/activesp/site.rb', line 145

def content_type(id)
  content_types.find { |t| t.id == id }
end

#content_typesArray<ContentType>

Returns the list of content types defined for this site. These include the content types defined on containing sites as they are automatically inherited

Returns:



136
137
138
139
140
141
# File 'lib/activesp/site.rb', line 136

def content_types
  result = call("Webs", "get_content_types", "listName" => @id)
  result.xpath("//sp:ContentType", NS).map do |content_type|
    supersite && supersite.content_type(content_type["ID"]) || ContentType.new(self, nil, content_type["ID"], content_type["Name"], content_type["Description"], content_type["Version"], content_type["Group"])
  end
end

#field(id) ⇒ Object



179
180
181
# File 'lib/activesp/site.rb', line 179

def field(id)
  fields.find { |f| f.ID == id }
end

#fieldsArray<Field>

Returns the list of fields for this site. This includes fields inherited from containing sites

Returns:



163
164
165
166
167
168
# File 'lib/activesp/site.rb', line 163

def fields
  call("Webs", "get_columns").xpath("//sp:Field", NS).map do |field|
    attributes = clean_attributes(field.attributes)
    supersite && supersite.field(attributes["ID"].downcase) || Field.new(self, attributes["ID"].downcase, attributes["StaticName"], attributes["Type"], nil, attributes) if attributes["ID"] && attributes["StaticName"]
  end.compact
end

#fields_by_nameHash{String => Field}

Returns the result of #fields hashed by name

Returns:

  • (Hash{String => Field})


173
174
175
# File 'lib/activesp/site.rb', line 173

def fields_by_name
  fields.inject({}) { |h, f| h[f.attributes["StaticName"]] = f ; h }
end

#is_root_site?Boolean

Returns true if this site is the root site

Returns:

  • (Boolean)


70
71
72
# File 'lib/activesp/site.rb', line 70

def is_root_site?
  @depth == 0
end

#keyString

See Base#key

Returns:

  • (String)


76
77
78
# File 'lib/activesp/site.rb', line 76

def key # This documentation is not ideal. The ideal doesn't work out of the box
  encode_key("S", [@url[@connection.root_url.length + 1..-1], @depth])
end

#list(name) ⇒ List

Returns the list with the given name. The name is what appears in the URL as name and is immutable. Returns nil if such a list does not exist

Parameters:

  • name (String)

    The name of the list

Returns:



122
123
124
# File 'lib/activesp/site.rb', line 122

def list(name)
  lists.find { |list| ::File.basename(list.url) == name }
end

#listsArray<List>

Returns the list if lists in this sute. Does not recurse

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/activesp/site.rb', line 101

def lists
  result1 = call("Lists", "get_list_collection")
  result2 = call("SiteData", "get_list_collection")
  result2_by_id = {}
  result2.xpath("//sp:_sList", NS).each do |element|
    data = {}
    element.children.each do |ch|
      data[ch.name] = ch.inner_text
    end
    result2_by_id[data["InternalName"]] = data
  end
  result1.xpath("//sp:List", NS).select { |list| list["Title"] != "User Information List" }.map do |list|
    List.new(self, list["ID"].to_s, list["Title"].to_s, clean_attributes(list.attributes), result2_by_id[list["ID"].to_s])
  end
end

#permission_setPermissionSet

Returns the permission set associated with this site. This returns the permission set of the containing site if it does not have a permission set of its own

Returns:



152
153
154
155
156
157
158
# File 'lib/activesp/site.rb', line 152

def permission_set
  if attributes["InheritedSecurity"]
    supersite.permission_set
  else
    PermissionSet.new(self)
  end
end

#relative_url(url = @url) ⇒ Object



48
49
50
# File 'lib/activesp/site.rb', line 48

def relative_url(url = @url)
  url[@connection.root_url.rindex("/") + 1..-1]
end

#rootsiteSite

Returns the root site, or this site if it is the root site

Returns:



63
64
65
# File 'lib/activesp/site.rb', line 63

def rootsite
  is_root_site? ? self : supersite.rootsite
end

#savevoid

This method returns an undefined value.

See Base#save



185
186
187
# File 'lib/activesp/site.rb', line 185

def save
  p untype_cast_attributes(self, nil, internal_attribute_types, changed_attributes)
end

#site(name) ⇒ Site

Returns the site with the given name. This name is what appears in the URL as name and is immutable. Return nil if such a site does not exist

Parameters:

  • name (String)

    The name if the site

Returns:



92
93
94
95
96
97
# File 'lib/activesp/site.rb', line 92

def site(name)
  result = call("Webs", "get_web", "webUrl" => ::File.join(@url, name))
  Site.new(connection, result.xpath("//sp:Web", NS).first["Url"].to_s, @depth + 1)
rescue Savon::SOAPFault
  nil
end

#sitesArray<List>

Returns the list of sites below this site. Does not recurse

Returns:



82
83
84
85
# File 'lib/activesp/site.rb', line 82

def sites
  result = call("Webs", "get_web_collection")
  result.xpath("//sp:Web", NS).map { |web| Site.new(connection, web["Url"].to_s, @depth + 1) }
end

#supersiteSite

Returns the containing site, or nil if this is the root site

Returns:



54
55
56
57
58
# File 'lib/activesp/site.rb', line 54

def supersite
  unless is_root_site?
    Site.new(@connection, ::File.dirname(@url), @depth - 1)
  end
end

#to_sObject Also known as: inspect



197
198
199
# File 'lib/activesp/site.rb', line 197

def to_s
  "#<ActiveSP::Site url=#{@url}>"
end