Class: ActiveSP::Site
Defined Under Namespace
Classes: Service
Instance Attribute Summary collapse
- #connection ⇒ Object readonly
-
#url ⇒ String
readonly
The URL of this site.
Instance Method Summary collapse
-
#/(name) ⇒ Site, List
Returns the site or list with the given name, or nil if it does not exist.
- #accessible? ⇒ Boolean
- #content_type(id) ⇒ Object
-
#content_types ⇒ Array<ContentType>
Returns the list of content types defined for this site.
- #field(id) ⇒ Object
-
#fields ⇒ Array<Field>
Returns the list of fields for this site.
-
#fields_by_name ⇒ Hash{String => Field}
Returns the result of #fields hashed by name.
-
#initialize(connection, url, depth = 0) ⇒ Site
constructor
A new instance of Site.
-
#is_root_site? ⇒ Boolean
Returns true if this site is the root site.
-
#key ⇒ String
See Base#key.
-
#list(name) ⇒ List
Returns the list with the given name.
-
#lists ⇒ Array<List>
Returns the list if lists in this sute.
-
#permission_set ⇒ PermissionSet
Returns the permission set associated with this site.
- #relative_url(url = @url) ⇒ Object
-
#rootsite ⇒ Site
Returns the root site, or this site if it is the root site.
-
#save ⇒ void
See Base#save.
-
#site(name) ⇒ Site
Returns the site with the given name.
-
#sites ⇒ Array<List>
Returns the list of sites below this site.
-
#supersite ⇒ Site
Returns the containing site, or nil if this is the root site.
- #to_s ⇒ Object (also: #inspect)
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
#connection ⇒ Object (readonly)
38 39 40 |
# File 'lib/activesp/site.rb', line 38 def connection @connection end |
#url ⇒ String (readonly)
The URL of this site
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
129 130 131 |
# File 'lib/activesp/site.rb', line 129 def /(name) list(name) || site(name) end |
#accessible? ⇒ 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_types ⇒ Array<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
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 |
#fields ⇒ Array<Field>
Returns the list of fields for this site. This includes fields inherited from containing sites
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_name ⇒ Hash{String => Field}
Returns the result of #fields hashed by name
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
70 71 72 |
# File 'lib/activesp/site.rb', line 70 def is_root_site? @depth == 0 end |
#key ⇒ String
See Base#key
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
122 123 124 |
# File 'lib/activesp/site.rb', line 122 def list(name) lists.find { |list| ::File.basename(list.url) == name } end |
#lists ⇒ Array<List>
Returns the list if lists in this sute. Does not recurse
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_set ⇒ PermissionSet
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
152 153 154 155 156 157 158 |
# File 'lib/activesp/site.rb', line 152 def if attributes["InheritedSecurity"] supersite. 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 |
#rootsite ⇒ Site
Returns the root site, or this site if it is the root site
63 64 65 |
# File 'lib/activesp/site.rb', line 63 def rootsite is_root_site? ? self : supersite.rootsite end |
#save ⇒ void
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
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 |
#sites ⇒ Array<List>
Returns the list of sites below this site. Does not recurse
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 |
#supersite ⇒ Site
Returns the containing site, or nil if this is the root site
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_s ⇒ Object Also known as: inspect
197 198 199 |
# File 'lib/activesp/site.rb', line 197 def to_s "#<ActiveSP::Site url=#{@url}>" end |