summaryrefslogtreecommitdiffhomepage
path: root/app/models
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-06-17 11:07:15 -0400
committerrealtradam <[email protected]>2024-06-17 11:07:15 -0400
commit23a972d8dec43dec1dc472a90d4749223e4aac00 (patch)
tree3ec62df7930e7095fd460eb4b4593334763575b5 /app/models
parent0855fce7d1960ff7aa1402d60504ca38feb0ff7e (diff)
downloadgameHolster-23a972d8dec43dec1dc472a90d4749223e4aac00.tar.gz
gameHolster-23a972d8dec43dec1dc472a90d4749223e4aac00.zip
update db initialization and bring back minor changes
Diffstat (limited to 'app/models')
-rw-r--r--app/models/game.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/game.rb b/app/models/game.rb
index 1eb75ff..e30dfae 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -1,3 +1,5 @@
+require "zip"
+
class Game < ApplicationRecord
enum status: { draft: 0, published: 1 }
#enum status: {
@@ -11,4 +13,27 @@ class Game < ApplicationRecord
has_one_attached :char_img
has_one_attached :title_img
has_and_belongs_to_many :tags
+
+ def save_zip(zip)
+ Zip::File.open(zip) do |zipfile|
+
+ zipfile.each do |entry|
+ if entry.file?
+ path_name = entry.name.rpartition('/')
+ name_extension = path_name.last.rpartition('.')
+
+ Tempfile.open([name_extension.first, name_extension[1] + name_extension.last]) do |temp_file|
+ entry.extract(temp_file.path) { true }
+ self.game_files.attach(io: File.open(temp_file.path), filename: path_name.last)
+ self.game_files.last.blob.filepath = path_name.first.delete_suffix('/').delete_prefix('/')
+
+ # saving the game wont have the blob saved so we need to do it manually
+ self.game_files.last.blob.save
+ end
+
+ end
+ end
+ end
+
+ end
end