pyu-activesp 0.0.4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,152 @@
1
+ # Copyright (c) 2010 XAOP bvba
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without
6
+ # restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the
9
+ # Software is furnished to do so, subject to the following
10
+ # conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ # OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ module ActiveSP
27
+
28
+ class ContentType < Base
29
+
30
+ include InSite
31
+ extend Caching
32
+ extend PersistentCaching
33
+ include Util
34
+
35
+ # @private
36
+ attr_reader :id
37
+
38
+ persistent { |site, list, id, *a| [site.connection, [:content_type, id]] }
39
+ # @private
40
+ def initialize(site, list, id, name = nil, description = nil, version = nil, group = nil)
41
+ @site, @list, @id = site, list, id
42
+ @Name = name if name
43
+ @Description = description if description
44
+ @Version = version if version
45
+ @Group = group if group
46
+ end
47
+
48
+ # Returns the scope of the content type. This can be either a site or a list
49
+ # @return [Site, List]
50
+ def scope
51
+ @list || @site
52
+ end
53
+
54
+ # Returns the supertype of this content type. This is the content type as defined on the containing
55
+ # site in case this content type has a list as scope. returns nil for a content type that has a site
56
+ # as scope
57
+ # @return [ContentType, nil]
58
+ def supertype
59
+ superkey = split_id[0..-2].join("")
60
+ (@list ? @list.content_type(superkey) : nil) || @site.content_type(superkey)
61
+ end
62
+ cache :supertype
63
+
64
+ # See {Base#key}
65
+ # @return [String]
66
+ def key
67
+ encode_key("T", [scope.key, @id])
68
+ end
69
+
70
+ # @private
71
+ def Name
72
+ data["Name"].to_s
73
+ end
74
+ cache :Name
75
+
76
+ # @private
77
+ def Description
78
+ data["Description"].to_s
79
+ end
80
+ cache :Description
81
+
82
+ # @private
83
+ def Version
84
+ data["Version"].to_s
85
+ end
86
+ cache :Version
87
+
88
+ # @private
89
+ def Group
90
+ data["Group"].to_s
91
+ end
92
+ cache :Group
93
+
94
+ # Returns the list of fields defined for this content type
95
+ # @return [Array<Field>]
96
+ def fields
97
+ data.xpath("//sp:Field", NS).map { |field| scope.field(field["ID"]) }.compact
98
+ end
99
+ cache :fields, :dup => :always
100
+
101
+ # See {Base#save}
102
+ # @return [void]
103
+ def save
104
+ p untype_cast_attributes(@site, nil, internal_attribute_types, changed_attributes)
105
+ end
106
+
107
+ # @private
108
+ def to_s
109
+ "#<ActiveSP::ContentType Name=#{self.Name}>"
110
+ end
111
+
112
+ # @private
113
+ alias inspect to_s
114
+
115
+ private
116
+
117
+ def data
118
+ if @list
119
+ call("Lists", "get_list_content_type", "listName" => @list.id, "contentTypeId" => @id).xpath("//sp:ContentType", NS).first
120
+ else
121
+ call("Webs", "get_content_type", "contentTypeId" => @id).xpath("//sp:ContentType", NS).first
122
+ end
123
+ end
124
+ cache :data
125
+
126
+ def original_attributes
127
+ type_cast_attributes(@site, nil, internal_attribute_types, clean_item_attributes(data.attributes))
128
+ end
129
+ cache :original_attributes
130
+
131
+ def internal_attribute_types
132
+ @@internal_attribute_types ||= {
133
+ "Description" => GhostField.new("ColName", "Text", false, true),
134
+ "FeatureId" => GhostField.new("ColName", "Text", false, true),
135
+ "Group" => GhostField.new("ColName", "Text", false, true),
136
+ "Hidden" => GhostField.new("Hidden", "Bool", false, true),
137
+ "ID" => GhostField.new("ColName", "Text", false, true),
138
+ "Name" => GhostField.new("ColName", "Text", false, true),
139
+ "ReadOnly" => GhostField.new("ReadOnly", "Bool", false, true),
140
+ "Sealed" => GhostField.new("Sealed", "Bool", false, true),
141
+ "V2ListTemplateName" => GhostField.new("V2ListTemplateName", "Text", false, true),
142
+ "Version" => GhostField.new("Version", "Integer", false, true)
143
+ }
144
+ end
145
+
146
+ def split_id
147
+ ["0x"] + @id[2..-1].scan(/[0-9A-F][1-9A-F]|[1-9A-F][0-9A-F]|00[0-9A-F]{32}/)
148
+ end
149
+
150
+ end
151
+
152
+ end
@@ -0,0 +1,193 @@
1
+ # Copyright (c) 2010 XAOP bvba
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without
6
+ # restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the
9
+ # Software is furnished to do so, subject to the following
10
+ # conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ # OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ module ActiveSP
27
+
28
+ class Field < Base
29
+
30
+ include InSite
31
+ extend Caching
32
+ include Util
33
+
34
+ # @private
35
+ attr_reader :ID, :Name, :internal_type
36
+ # Returns the scope of the field. This can be a site or a list
37
+ # @return [Site, List]
38
+ attr_reader :scope
39
+ # Returns the parent field. This is the field defined on the containing site in case the field has a list as scope
40
+ # @return [Field]
41
+ attr_reader :parent
42
+
43
+ # There is no call to get to the field info directly, so these should always
44
+ # be accessed through the site or list they belong to. Hence, we do not use
45
+ # caching here as it is useless.
46
+ # @private
47
+ def initialize(scope, id, name, type, parent, attributes_before_type_cast)
48
+ @scope, @ID, @Name, @internal_type, @parent, @attributes_before_type_cast = scope, id, name, type, parent, attributes_before_type_cast
49
+ @site = Site === @scope ? @scope : @scope.site
50
+ end
51
+
52
+ # See {Base#key}
53
+ # @return [String]
54
+ def key
55
+ encode_key("A", [@scope.key, @ID])
56
+ end
57
+
58
+ # @private
59
+ def List
60
+ list_for_lookup
61
+ end
62
+
63
+ # @private
64
+ def Type
65
+ translate_internal_type(self)
66
+ end
67
+
68
+ # @private
69
+ def Mult
70
+ !!attributes["Mult"]
71
+ end
72
+
73
+ # @private
74
+ def ReadOnly
75
+ !!attributes["ReadOnly"]
76
+ end
77
+
78
+ # See {Base#save}
79
+ # @return [void]
80
+ def save
81
+ p untype_cast_attributes(@site, nil, internal_attribute_types, changed_attributes)
82
+ end
83
+
84
+ # @private
85
+ def to_s
86
+ "#<ActiveSP::Field name=#{self.Name}>"
87
+ end
88
+
89
+ # @private
90
+ alias inspect to_s
91
+
92
+ private
93
+
94
+ def list_for_lookup
95
+ # I think List may be undefined for attributes defined at the site level, and that they need to be specified
96
+ # when used at the list level.
97
+ if %w[Lookup LookupMulti].include?(@internal_type) and list = @attributes_before_type_cast["List"]
98
+ if list[0] == ?{ && list[-1] == ?} # We have a GUID of a list
99
+ ActiveSP::List.new(@site, list)
100
+ elsif list == "Self"
101
+ List === @scope ? @scope : nil
102
+ end
103
+ end
104
+ end
105
+
106
+ def original_attributes
107
+ @original_attributes ||= type_cast_attributes(@site, nil, internal_attribute_types, @attributes_before_type_cast.merge("List" => list_for_lookup, "Type" => self.Type, "internal_type" => internal_type))
108
+ end
109
+
110
+ def internal_attribute_types
111
+ @@internal_attribute_types ||= {
112
+ "AllowDeletion" => GhostField.new("AllowDeletion", "Bool", false, true),
113
+ "AppendOnly" => GhostField.new("AppendOnly", "Bool", false, true),
114
+ "AuthoringInfo" => GhostField.new("AuthoringInfo", "Text", false, true),
115
+ "CalType" => GhostField.new("CalType", "Integer", false, true),
116
+ "CanToggleHidden" => GhostField.new("CanToggleHidden", "Bool", false, true),
117
+ "ClassInfo" => GhostField.new("ClassInfo", "Text", false, true),
118
+ "ColName" => GhostField.new("ColName", "Text", false, true),
119
+ "Description" => GhostField.new("Description", "Text", false, true),
120
+ "Dir" => GhostField.new("Dir", "Text", false, true),
121
+ "DisplaceOnUpgrade" => GhostField.new("DisplaceOnUpgrade", "Bool", false, true),
122
+ "DisplayImage" => GhostField.new("DisplayImage", "Text", false, true),
123
+ "DisplayName" => GhostField.new("DisplayName", "Text", false, true),
124
+ "DisplayNameSrcField" => GhostField.new("DisplayNameSrcField", "Text", false, true),
125
+ "DisplaySize" => GhostField.new("DisplaySize", "Integer", false, true),
126
+ "ExceptionImage" => GhostField.new("ExceptionImage", "Text", false, true),
127
+ "FieldRef" => GhostField.new("FieldRef", "Text", false, true),
128
+ "FillInChoice" => GhostField.new("FillInChoice", "Bool", false, true),
129
+ "Filterable" => GhostField.new("Filterable", "Bool", false, true),
130
+ "Format" => GhostField.new("Format", "Bool", false, true),
131
+ "FromBaseType" => GhostField.new("FromBaseType", "Bool", false, true),
132
+ "Group" => GhostField.new("Group", "Text", false, true),
133
+ "HeaderImage" => GhostField.new("HeaderImage", "Text", false, true),
134
+ "Height" => GhostField.new("Height", "Integer", false, true),
135
+ "Hidden" => GhostField.new("Hidden", "Bool", false, true),
136
+ "ID" => GhostField.new("ID", "Text", false, true),
137
+ "IMEMode" => GhostField.new("IMEMode", "Text", false, true),
138
+ "internal_type" => GhostField.new("internal_type", "Text", false, true),
139
+ "IsolateStyles" => GhostField.new("IsolateStyles", "Bool", false, true),
140
+ "JoinColName" => GhostField.new("JoinColName", "Text", false, true),
141
+ "JoinRowOrdinal" => GhostField.new("JoinRowOrdinal", "Integer", false, true),
142
+ "JoinType" => GhostField.new("JoinType", "Text", false, true),
143
+ "List" => GhostField.new("List", "ListReference", false, true),
144
+ "Max" => GhostField.new("Max", "Integer", false, true),
145
+ "MaxLength" => GhostField.new("MaxLength", "Integer", false, true),
146
+ "Min" => GhostField.new("Min", "Integer", false, true),
147
+ "Mult" => GhostField.new("Mult", "Bool", false, true),
148
+ "Name" => GhostField.new("Name", "Text", false, true),
149
+ "Node" => GhostField.new("Node", "Text", false, true),
150
+ "NoEditFormBreak" => GhostField.new("NoEditFormBreak", "Bool", false, true),
151
+ "NumLines" => GhostField.new("NumLines", "Text", false, true),
152
+ "Percentage" => GhostField.new("Percentage", "Bool", false, true),
153
+ "PIAttribute" => GhostField.new("PIAttribute", "Text", false, true),
154
+ "PITarget" => GhostField.new("PITarget", "Text", false, true),
155
+ "PrependId" => GhostField.new("PrependId", "Bool", false, true),
156
+ "PrimaryKey" => GhostField.new("PrimaryKey", "Bool", false, true),
157
+ "PrimaryPIAttribute" => GhostField.new("PrimaryPIAttribute", "Text", false, true),
158
+ "PrimaryPITarget" => GhostField.new("PrimaryPITarget", "Text", false, true),
159
+ "ReadOnly" => GhostField.new("ReadOnly", "Bool", false, true),
160
+ "ReadOnlyEnforced" => GhostField.new("ReadOnlyEnforced", "Bool", false, true),
161
+ "RenderXMLUsingPattern" => GhostField.new("ReadOnly", "Bool", false, true),
162
+ "Required" => GhostField.new("Required", "Bool", false, true),
163
+ "RestrictedMode" => GhostField.new("RestrictedMode", "Bool", false, true),
164
+ "RichText" => GhostField.new("RichText", "Bool", false, true),
165
+ "RichTextMode" => GhostField.new("RichTextMode", "Text", false, true),
166
+ "RowOrdinal" => GhostField.new("RowOrdinal", "Integer", false, true),
167
+ "Sealed" => GhostField.new("Sealed", "Bool", false, true),
168
+ "ShowInDisplayForm" => GhostField.new("ShowInDisplayForm", "Bool", false, true),
169
+ "ShowInListSettings" => GhostField.new("ShowInListSettings", "Bool", false, true),
170
+ "ShowInFileDlg" => GhostField.new("ShowInFileDlg", "Bool", false, true),
171
+ "ShowInVersionHistory" => GhostField.new("ShowInVersionHistory", "Bool", false, true),
172
+ "Sortable" => GhostField.new("Sortable", "Bool", false, true),
173
+ "SourceID" => GhostField.new("SourceID", "Text", false, true),
174
+ "StaticName" => GhostField.new("StaticName", "Text", false, true),
175
+ "StorageTZ" => GhostField.new("StorageTZ", "Bool", false, true),
176
+ "TextOnly" => GhostField.new("TextOnly", "Bool", false, true),
177
+ "Title" => GhostField.new("Title", "Text", false, true),
178
+ "Type" => GhostField.new("Type", "Text", false, true),
179
+ "SetAs" => GhostField.new("SetAs", "Text", false, true),
180
+ "ShowField" => GhostField.new("ShowField", "Text", false, true),
181
+ "ShowInEditForm" => GhostField.new("ShowInEditForm", "Bool", false, true),
182
+ "ShowInNewForm" => GhostField.new("ShowInNewForm", "Bool", false, true),
183
+ "UnlimitedLengthInDocumentLibrary" => GhostField.new("UnlimitedLengthInDocumentLibrary", "Bool", false, true),
184
+ "Version" => GhostField.new("Version", "Integer", false, true),
185
+ "Width" => GhostField.new("Width", "Integer", false, true),
186
+ "WikiLinking" => GhostField.new("WikiLinking", "Bool", false, true),
187
+ "XName" => GhostField.new("XName", "Text", false, true)
188
+ }
189
+ end
190
+
191
+ end
192
+
193
+ end
@@ -0,0 +1,71 @@
1
+ # Copyright (c) 2010 XAOP bvba
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without
6
+ # restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the
9
+ # Software is furnished to do so, subject to the following
10
+ # conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ # OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ module ActiveSP
27
+
28
+ class File
29
+
30
+ include InSite
31
+
32
+ attr_reader :url
33
+
34
+ def initialize(item, url, destroyable)
35
+ @item, @url, @destroyable = item, url, destroyable
36
+ @site = @item.list.site
37
+ end
38
+
39
+ def file_name
40
+ ::File.basename(@url)
41
+ end
42
+
43
+ def data
44
+ @item.list.site.connection.fetch(@url).body
45
+ end
46
+
47
+ def destroy
48
+ if @destroyable
49
+ result = call("Lists", "delete_attachment", "listName" => @item.list.id, "listItemID" => @item.ID, "url" => @url)
50
+ if delete_result = result.xpath("//sp:DeleteAttachmentResponse", NS).first
51
+ self
52
+ else
53
+ raise "file could not be deleted"
54
+ end
55
+ else
56
+ raise TypeError, "this file cannot be destroyed"
57
+ end
58
+ end
59
+
60
+ # @private
61
+ def to_s
62
+ "#<ActiveSP::File url=#{@url}>"
63
+ end
64
+
65
+ # @private
66
+ alias inspect to_s
67
+
68
+ end
69
+
70
+ end
71
+
@@ -0,0 +1,103 @@
1
+ # Copyright (c) 2010 XAOP bvba
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without
6
+ # restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the
9
+ # Software is furnished to do so, subject to the following
10
+ # conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ # OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ module ActiveSP
27
+
28
+ class Folder < Item
29
+
30
+ # See {Base#key}
31
+ # @return [String]
32
+ def key
33
+ encode_key("F", [@list.key, @id])
34
+ end
35
+
36
+ def is_folder?
37
+ false
38
+ end
39
+
40
+ # Returns the list of items in this folder
41
+ # @param [Hash] options See {List#each_item}, :folder option has no effect
42
+ # @return [Array<Item>]
43
+ def each_item(options = {}, &blk)
44
+ @list.each_item(options.merge(:folder => self), &blk)
45
+ end
46
+ association :items
47
+
48
+ def each_folder(options = {}, &blk)
49
+ @list.each_folder(options.merge(:folder => self), &blk)
50
+ end
51
+ association :folders do
52
+ def create(parameters = {})
53
+ @object.create_folder(parameters)
54
+ end
55
+ end
56
+
57
+ def create_folder(parameters = {})
58
+ @list.create_folder(parameters.merge(:folder => absolute_url))
59
+ end
60
+
61
+ def each_document(options = {}, &blk)
62
+ @list.each_document(options.merge(:folder => self), &blk)
63
+ end
64
+ association :documents do
65
+ def create(parameters = {})
66
+ @object.create_document(parameters)
67
+ end
68
+ end
69
+
70
+ def create_document(parameters = {})
71
+ @list.create_document(parameters.merge(:folder => absolute_url))
72
+ end
73
+
74
+ # Returns the item with the given name
75
+ # @param [String] name
76
+ # @return [Item]
77
+ def item(name)
78
+ query = Builder::XmlMarkup.new.Query do |xml|
79
+ xml.Where do |xml|
80
+ xml.Eq do |xml|
81
+ xml.FieldRef(:Name => "FileLeafRef")
82
+ xml.Value(name, :Type => "Text")
83
+ end
84
+ end
85
+ end
86
+ items(:query => query).first
87
+ end
88
+
89
+ alias / item
90
+
91
+ undef content
92
+
93
+ # @private
94
+ def to_s
95
+ "#<ActiveSP::Folder url=#{url}>"
96
+ end
97
+
98
+ # @private
99
+ alias inspect to_s
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,100 @@
1
+ # Copyright (c) 2010 XAOP bvba
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without
6
+ # restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the
9
+ # Software is furnished to do so, subject to the following
10
+ # conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ #
22
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ # OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ module ActiveSP
27
+
28
+ # This class represents the field definitions for objects in SharePoint for which the
29
+ # fields cannot be changed and are thus not represented by an object in SharePoint.
30
+ # These include fields of sites, lists, users, grouos, roles, content types and fields.
31
+ # The interface of this class is not as complete as the interface if a Field, mainly
32
+ # because it does not make much sense to do so
33
+ class GhostField
34
+
35
+ include Util
36
+
37
+ # @private
38
+ attr_reader :Name, :internal_type, :Mult, :ReadOnly
39
+
40
+ # @private
41
+ def initialize(name, type, mult, read_only)
42
+ @Name, @internal_type, @Mult, @ReadOnly = name, type, mult, read_only
43
+ end
44
+
45
+ # @private
46
+ def Type
47
+ translate_internal_type(self)
48
+ end
49
+
50
+ # Returns the attributes of this object as a Hash
51
+ # @return [Hash{String => Integer, Float, String, Time, Boolean, Base}]
52
+ def attributes
53
+ original_attributes.dup
54
+ end
55
+
56
+ # Returns the value of the attribute of the given name, or nil if this object does not have an attribute by the given name
57
+ # @param [String] name The name of the attribute
58
+ # @return [Integer, Float, String, Time, Boolean, Base]
59
+ def attribute(name)
60
+ current_attributes[name]
61
+ end
62
+
63
+ # Returns whether or not this object has an attribute with the given name
64
+ # @param [String] name The name of the attribute
65
+ # @return [Boolean]
66
+ def has_attribute?(name)
67
+ current_attributes.has_key?(name)
68
+ end
69
+
70
+ # See {Base#method_missing}
71
+ def method_missing(m, *a, &b)
72
+ ms = m.to_s
73
+ if a.length == 0 && has_attribute?(ms)
74
+ attribute(ms)
75
+ else
76
+ super
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def current_attributes
83
+ original_attributes
84
+ end
85
+
86
+ def original_attributes
87
+ @original_attributes ||= {
88
+ "ColName" => @Name,
89
+ "DisplayName" => @Name,
90
+ "Mult" => @Mult,
91
+ "Name" => @Name,
92
+ "ReadOnly" => @ReadOnly,
93
+ "StaticName" => @Name,
94
+ "Type" => self.Type
95
+ }
96
+ end
97
+
98
+ end
99
+
100
+ end