lib/siteleaf/file.rb in siteleaf-2.0.0.pre.beta7 vs lib/siteleaf/file.rb in siteleaf-2.0.0.pre.beta9
- old
+ new
@@ -1,9 +1,28 @@
module Siteleaf
- class File < Asset
-
+ class File < Entity
+
+ attr_accessor :file, :filename, :path, :collection_path, :site_id, :user_id
+ attr_reader :id, :basename, :directory, :url, :download_url, :thumbnail_url, :content_type, :filesize, :sha, :created_at, :updated_at
+
def create_endpoint
- "sites/#{self.site_id}/files"
+ ::File.join("sites", site_id, "collections", collection_identifier, "files")
+ end
+
+ def site
+ Site.find(site_id) if site_id
+ end
+
+ def collection
+ Collection.find(collection_identifier)
+ end
+
+ def collection_identifier
+ collection_path || (directory && directory.match(/_(.*)/).try(:last))
+ end
+
+ def to_file
+ SourceFile.new(site_id: site_id, name: filename).to_file
end
end
end
\ No newline at end of file