created file sync

This commit is contained in:
Senad Uka
2016-02-21 19:17:04 +01:00
parent 709ce3e38c
commit ac099e3210
18 changed files with 230 additions and 28 deletions

View File

@@ -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

View File

@@ -1,3 +1,7 @@
class FileType < ActiveRecord::Base
has_many :configuration_files
def to_s
name
end
end