Class: SakaiInfo::WikiPage
Instance Attribute Summary collapse
Attributes inherited from SakaiObject
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from SakaiObject
#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml
Constructor Details
#initialize(dbrow) ⇒ WikiPage
Returns a new instance of WikiPage.
21
22
23
24
25
|
# File 'lib/sakai-info/wiki.rb', line 21
def initialize(dbrow)
@dbrow = dbrow
@id = dbrow[:id]
end
|
Instance Attribute Details
#dbrow ⇒ Object
Returns the value of attribute dbrow.
14
15
16
|
# File 'lib/sakai-info/wiki.rb', line 14
def dbrow
@dbrow
end
|
Class Method Details
.all_serializations ⇒ Object
216
217
218
219
220
221
222
223
|
# File 'lib/sakai-info/wiki.rb', line 216
def self.all_serializations
[
:default,
:permissions,
:content,
:history,
]
end
|
.clear_cache ⇒ Object
16
17
18
|
# File 'lib/sakai-info/wiki.rb', line 16
def self.clear_cache
@@cache = {}
end
|
.find(id) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/sakai-info/wiki.rb', line 27
def self.find(id)
if @@cache[id].nil?
row = DB.connect[:rwikiobject].filter(:id => id).first
if row.nil?
raise ObjectNotFoundException.new(WikiPage, id)
end
@@cache[id] = WikiPage.new(row)
end
@@cache[id]
end
|
Instance Method Details
#content ⇒ Object
138
139
140
|
# File 'lib/sakai-info/wiki.rb', line 138
def content
@content ||= DB.connect[:rwikicurrentcontent].where(:rwikiid => self.id).first[:content].read
end
|
#content_serialization ⇒ Object
210
211
212
213
214
|
# File 'lib/sakai-info/wiki.rb', line 210
def content_serialization
{
"content" => self.content,
}
end
|
#default_serialization ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/sakai-info/wiki.rb', line 147
def default_serialization
result = {
"id" => self.id,
"page_name" => self.page_name,
"realm" => self.realm.serialize(:summary),
"owner" => self.owner.eid,
"last_updated_by" => self.last_updated_by.eid,
"last_updated" => self.last_updated,
"site" => self.site.serialize(:summary),
"permissions" => self.permission_string,
"revision" => self.revision,
}
result
end
|
#group_admin? ⇒ Boolean
114
115
116
|
# File 'lib/sakai-info/wiki.rb', line 114
def group_admin?
@dbrow[:groupadmin] == 1
end
|
#group_readable? ⇒ Boolean
106
107
108
|
# File 'lib/sakai-info/wiki.rb', line 106
def group_readable?
@dbrow[:groupread] == 1
end
|
#group_writable? ⇒ Boolean
110
111
112
|
# File 'lib/sakai-info/wiki.rb', line 110
def group_writable?
@dbrow[:groupwrite] == 1
end
|
#history_serialization ⇒ Object
200
201
202
203
204
205
206
207
208
|
# File 'lib/sakai-info/wiki.rb', line 200
def history_serialization
result = {
"history" => self.history.collect { |r| r.serialize(:history) },
}
if result["history"] == []
result = {}
end
result
end
|
#history_summary_serialization ⇒ Object
171
172
173
174
175
176
177
|
# File 'lib/sakai-info/wiki.rb', line 171
def history_summary_serialization
{
"id" => self.id,
"last_updated" => self.last_updated,
"last_updated_by" => self.last_updated_by.eid,
}
end
|
#last_updated ⇒ Object
38
39
40
|
# File 'lib/sakai-info/wiki.rb', line 38
def last_updated
@dbrow[:version]
end
|
#last_updated_by ⇒ Object
50
51
52
|
# File 'lib/sakai-info/wiki.rb', line 50
def last_updated_by
@updated_by ||= User.find!(@dbrow[:userid])
end
|
#owner ⇒ Object
46
47
48
|
# File 'lib/sakai-info/wiki.rb', line 46
def owner
@owner ||= User.find!(@dbrow[:owner])
end
|
#owner_admin? ⇒ Boolean
102
103
104
|
# File 'lib/sakai-info/wiki.rb', line 102
def owner_admin?
@dbrow[:owneradmin] == 1
end
|
#owner_readable? ⇒ Boolean
94
95
96
|
# File 'lib/sakai-info/wiki.rb', line 94
def owner_readable?
@dbrow[:ownerread] == 1
end
|
#owner_writable? ⇒ Boolean
98
99
100
|
# File 'lib/sakai-info/wiki.rb', line 98
def owner_writable?
@dbrow[:ownerwrite] == 1
end
|
#page_name ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/sakai-info/wiki.rb', line 84
def page_name
@page_name ||= if not self.realm_name.nil?
if @dbrow[:name] =~ /^#{self.realm_name}\/(.+)$/
$1
else
@dbrow[:name]
end
end
end
|
#permission_string ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/sakai-info/wiki.rb', line 126
def permission_string
(self.owner_readable? ? "r" : "-") +
(self.owner_writable? ? "w" : "-") +
(self.owner_admin? ? "A" : "-") +
(self.group_readable? ? "r" : "-") +
(self.group_writable? ? "w" : "-") +
(self.group_admin? ? "A" : "-") +
(self.public_readable? ? "r" : "-") +
(self.public_writable? ? "w" : "-") +
"-"
end
|
#permissions_serialization ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/sakai-info/wiki.rb', line 179
def permissions_serialization
{
"permissions" => {
"owner" => {
"read" => self.owner_readable?,
"write" => self.owner_writable?,
"admin" => self.owner_admin?,
},
"group" => {
"read" => self.group_readable?,
"write" => self.group_writable?,
"admin" => self.group_admin?,
},
"public" => {
"read" => self.public_readable?,
"write" => self.public_writable?,
}
}
}
end
|
#public_readable? ⇒ Boolean
118
119
120
|
# File 'lib/sakai-info/wiki.rb', line 118
def public_readable?
@dbrow[:publicread] == 1
end
|
#public_writable? ⇒ Boolean
122
123
124
|
# File 'lib/sakai-info/wiki.rb', line 122
def public_writable?
@dbrow[:publicwrite] == 1
end
|
#realm ⇒ Object
54
55
56
57
58
|
# File 'lib/sakai-info/wiki.rb', line 54
def realm
if not self.realm_name.nil?
@realm ||= AuthzRealm.find!(self.realm_name)
end
end
|
#realm_name ⇒ Object
60
61
62
|
# File 'lib/sakai-info/wiki.rb', line 60
def realm_name
@dbrow[:realm]
end
|
#revision ⇒ Object
42
43
44
|
# File 'lib/sakai-info/wiki.rb', line 42
def revision
@dbrow[:revision]
end
|
#site ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/sakai-info/wiki.rb', line 76
def site
@site ||= if not self.site_id.nil?
Site.find!(self.site_id)
else
nil
end
end
|
#site_id ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/sakai-info/wiki.rb', line 64
def site_id
@site_id ||= if not self.realm_name.nil?
if self.realm_name =~ /^\/site\/([^\/]+)/
$1
else
nil
end
else
nil
end
end
|
#summary_serialization ⇒ Object
162
163
164
165
166
167
168
169
|
# File 'lib/sakai-info/wiki.rb', line 162
def summary_serialization
{
"id" => self.id,
"name" => self.name,
"owner" => self.owner.eid,
"site_id" => self.site_id,
}
end
|