Class: SakaiInfo::Announcement
- Inherits:
-
SakaiObject
- Object
- SakaiObject
- SakaiInfo::Announcement
- Defined in:
- lib/sakai-info/announcement.rb
Instance Attribute Summary collapse
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#dbrow ⇒ Object
readonly
Returns the value of attribute dbrow.
-
#draft ⇒ Object
readonly
Returns the value of attribute draft.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#pubview ⇒ Object
readonly
Returns the value of attribute pubview.
Attributes inherited from SakaiObject
Class Method Summary collapse
- .all_serializations ⇒ Object
- .clear_cache ⇒ Object
- .count_by_channel_id(channel_id) ⇒ Object
- .find(id) ⇒ Object
- .find_by_channel_id(channel_id) ⇒ Object
- .query_by_channel_id(channel_id) ⇒ Object
Instance Method Summary collapse
-
#channel ⇒ Object
lazy properties.
-
#default_serialization ⇒ Object
serialization.
-
#initialize(dbrow) ⇒ Announcement
constructor
A new instance of Announcement.
- #summary_serialization ⇒ Object
- #xml ⇒ Object
- #xml_serialization ⇒ Object
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) ⇒ Announcement
Returns a new instance of Announcement.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/sakai-info/announcement.rb', line 115 def initialize(dbrow) @dbrow = dbrow @id = @dbrow[:message_id] @channel_id = @dbrow[:channel_id] @draft = @dbrow[:draft] @pubview = @dbrow[:pubview] @owner = User.find(@dbrow[:owner]) @date = @dbrow[:message_date] end |
Instance Attribute Details
#channel_id ⇒ Object (readonly)
Returns the value of attribute channel_id.
108 109 110 |
# File 'lib/sakai-info/announcement.rb', line 108 def channel_id @channel_id end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
108 109 110 |
# File 'lib/sakai-info/announcement.rb', line 108 def date @date end |
#dbrow ⇒ Object (readonly)
Returns the value of attribute dbrow.
108 109 110 |
# File 'lib/sakai-info/announcement.rb', line 108 def dbrow @dbrow end |
#draft ⇒ Object (readonly)
Returns the value of attribute draft.
108 109 110 |
# File 'lib/sakai-info/announcement.rb', line 108 def draft @draft end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
108 109 110 |
# File 'lib/sakai-info/announcement.rb', line 108 def owner @owner end |
#pubview ⇒ Object (readonly)
Returns the value of attribute pubview.
108 109 110 |
# File 'lib/sakai-info/announcement.rb', line 108 def pubview @pubview end |
Class Method Details
.all_serializations ⇒ Object
189 190 191 192 193 194 |
# File 'lib/sakai-info/announcement.rb', line 189 def self.all_serializations [ :default, :xml, ] end |
.clear_cache ⇒ Object
110 111 112 |
# File 'lib/sakai-info/announcement.rb', line 110 def self.clear_cache @@cache = {} end |
.count_by_channel_id(channel_id) ⇒ Object
141 142 143 |
# File 'lib/sakai-info/announcement.rb', line 141 def self.count_by_channel_id(channel_id) Announcement.query_by_channel_id(channel_id).count end |
.find(id) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/sakai-info/announcement.rb', line 126 def self.find(id) if @@cache[id].nil? row = DB.connect[:announcement_message].where(:message_id => id).first if row.nil? raise ObjectNotFoundException.new(Announcement, id) end @@cache[id] = Announcement.new(row) end @@cache[id] end |
.find_by_channel_id(channel_id) ⇒ Object
145 146 147 148 149 |
# File 'lib/sakai-info/announcement.rb', line 145 def self.find_by_channel_id(channel_id) Announcement.query_by_channel_id(channel_id).all.collect do |row| @@cache[row[:message_id]] = Announcement.new(row) end end |
Instance Method Details
#channel ⇒ Object
lazy properties
152 153 154 |
# File 'lib/sakai-info/announcement.rb', line 152 def channel @channel ||= AnnouncementChannel.find(self.channel_id) end |
#default_serialization ⇒ Object
serialization
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/sakai-info/announcement.rb', line 165 def default_serialization { "id" => self.id, "date" => self.date, "owner" => self.owner.serialize(:summary), "draft" => self.draft, "pubview" => self.pubview, "channel" => self.channel_id, } end |
#summary_serialization ⇒ Object
176 177 178 179 180 181 |
# File 'lib/sakai-info/announcement.rb', line 176 def summary_serialization { "id" => self.id, "date" => self.date } end |
#xml ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/sakai-info/announcement.rb', line 156 def xml if @xml.nil? @xml = "" REXML::Document.new(@dbrow[:xml].read).write(@xml, 2) end @xml end |
#xml_serialization ⇒ Object
183 184 185 186 187 |
# File 'lib/sakai-info/announcement.rb', line 183 def xml_serialization { "xml" => self.xml } end |