Class: SakaiInfo::ContentResource
- Inherits:
-
Content
- Object
- SakaiObject
- Content
- SakaiInfo::ContentResource
- Defined in:
- lib/sakai-info/content.rb
Constant Summary collapse
- @@cache =
{}
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#resource_type_id ⇒ Object
readonly
Returns the value of attribute resource_type_id.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Attributes inherited from Content
Attributes inherited from SakaiObject
Class Method Summary collapse
Instance Method Summary collapse
- #default_serialization ⇒ Object
-
#initialize(id, parent_id, file_path, uuid, file_size, context, resource_type_id) ⇒ ContentResource
constructor
A new instance of ContentResource.
- #size_on_disk ⇒ Object
Methods inherited from Content
#binary, #effective_realm, #parent, #realm, #summary_serialization
Methods inherited from SakaiObject
all_serializations, #dbrow_only_serialization, #dbrow_serialization, #object_type_serialization, #serialize, #to_json, #to_yaml
Constructor Details
#initialize(id, parent_id, file_path, uuid, file_size, context, resource_type_id) ⇒ ContentResource
Returns a new instance of ContentResource.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sakai-info/content.rb', line 89 def initialize(id, parent_id, file_path, uuid, file_size, context, resource_type_id) @id = id @parent_id = parent_id @file_path = File.join(Instance.content_base_directory, file_path) @uuid = uuid @file_size = file_size @context = context @resource_type_id = resource_type_id @table_name = "content_resource" @id_column = "resource_id" end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
87 88 89 |
# File 'lib/sakai-info/content.rb', line 87 def context @context end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
87 88 89 |
# File 'lib/sakai-info/content.rb', line 87 def file_path @file_path end |
#resource_type_id ⇒ Object (readonly)
Returns the value of attribute resource_type_id.
87 88 89 |
# File 'lib/sakai-info/content.rb', line 87 def resource_type_id @resource_type_id end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
87 88 89 |
# File 'lib/sakai-info/content.rb', line 87 def uuid @uuid end |
Class Method Details
.count_by_parent(parent_id) ⇒ Object
143 144 145 |
# File 'lib/sakai-info/content.rb', line 143 def self.count_by_parent(parent_id) DB.connect[:content_resource].filter(:in_collection => parent_id).count end |
.find(id) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/sakai-info/content.rb', line 103 def self.find(id) if @@cache[id].nil? row = DB.connect[:content_resource].filter(:resource_id => id).first if row.nil? raise ObjectNotFoundException.new(ContentResource, id) end @@cache[id] = ContentResource.new(row[:resource_id], row[:in_collection], row[:file_path], row[:resource_uuid], row[:file_size].to_i, row[:context], row[:resource_type_id]) end @@cache[id] end |
.find_by_parent(parent_id) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/sakai-info/content.rb', line 131 def self.find_by_parent(parent_id) resources = [] DB.connect[:content_resource].filter(:in_collection => parent_id) do |row| @@cache[row[:resource_id]] = ContentResource.new(row[:resource_id], row[:in_collection], row[:file_path], row[:resource_uuid], row[:file_size].to_i, row[:context], row[:resource_type_id]) resources << @@cache[row[0]] end resources end |
Instance Method Details
#default_serialization ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/sakai-info/content.rb', line 118 def default_serialization { "id" => self.id, "parent" => self.parent_id, "uuid" => self.uuid, "file_path" => self.file_path, "size_on_disk" => self.size_on_disk, "context" => self.context, "resource_type_id" => self.resource_type_id, "effective_realm" => (self.effective_realm.nil? ? nil : self.effective_realm.name) } end |
#size_on_disk ⇒ Object
114 115 116 |
# File 'lib/sakai-info/content.rb', line 114 def size_on_disk @file_size end |