created file sync
This commit is contained in:
@@ -1,5 +1,33 @@
|
||||
class ConfigurationFile < ActiveRecord::Base
|
||||
belongs_to :server
|
||||
belongs_to :file_type
|
||||
has_many :file_versions
|
||||
has_many :file_versions, -> { order('number DESC') }
|
||||
|
||||
def self.create_from_template!(template, server_id)
|
||||
file = ConfigurationFile.new
|
||||
file.server_id = server_id
|
||||
file.file_path = template.file_path
|
||||
file.file_type = template.file_type
|
||||
file.namehash = SecureRandom.hex
|
||||
transaction do
|
||||
file.save!
|
||||
file.file_versions.create!(content: template.content)
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
def update_by_form(content, path)
|
||||
transaction do
|
||||
update_attribute(:file_path, path)
|
||||
file_versions.create!(content: content, number: last_version.number + 1)
|
||||
end
|
||||
end
|
||||
|
||||
def update_by_api(file)
|
||||
file_versions.create!(content: file.read, number: last_version.number + 1)
|
||||
end
|
||||
|
||||
def last_version
|
||||
file_versions.first
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
class FileType < ActiveRecord::Base
|
||||
has_many :configuration_files
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user