You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.5 KiB

2 months ago
require "sequel"
cfg_internal = IniConfig.new()
Sequel.connect(cfg_internal.get_db)
class Repos < Sequel::Model(:repos)
end
class Recips < Sequel::Model(:recips)
end
class RepocRecips < Sequel::Model(:repos_recips)
end
class Projects < Sequel::Model(:projects)
end
class ReposProjects < Sequel::Model(:repos_projects)
end
2 months ago
class DBase
attr :error, :last_id
def creategit(project_name, description)
@error = nil
data = Repos.where(reponame: project_name).first
if data.nil?
2 months ago
id = Repos.insert(reponame: project_name, descr: description, public: 1)
@last_id = id
else
@error = "Данный репозиторий уже существует"
end
@error
end
def get_repo_info_by_name(repo_name)
Repos.where(reponame: repo_name)
end
def get_recips()
result = []
Recips.order(:id).map do |item|
{ :fname => item[:filepath], :descr => item[:descr], :id => item[:id] }
end
end
def delete_repo_by_name(repo_name)
rep_id = Repos.where(reponame: repo_name).first
unless rep_id[:id].nil?
id = rep_id[:id]
RepocRecips.where(repo_id: id).delete
Repos.where(id: id).delete
end
end
def createrecip(filepath, description, codedata, gitlist)
error_data = nil
filepath_san = sanitize_rcptname(filepath)
is_data = Recips.where(filepath: filepath_san).first
if codedata.nil? || codedata.strip == ""
error_data
else
if is_data.nil?
id = Recips.insert(filepath: filepath_san, descr: description, content: codedata)
@last_id = id
if !gitlist.nil? && gitlist.length > 0
gitlist.each do |item|
data = Repos.where(id: item.to_i).first
unless data.nil?
RepocRecips.insert(repo_id: data[:id], recip_id: id)
end
end
end
error_data
else
"Рецепт с таким именем #{filepath_san} уже существует"
end
end
end
def updaterecip(id, filepath, description, codedata, gitlist)
error_data = nil
filepath_san = sanitize_rcptname(filepath)
is_data = Recips.where(filepath: filepath_san).first
if codedata.nil? || codedata.strip == ""
error_data
else
unless is_data.nil?
Recips.where(id: id.to_i).update(filepath: filepath_san, descr: description, content: codedata)
RepocRecips.where(recip_id: id.to_i).delete
if !gitlist.nil? && gitlist.length > 0
gitlist.each do |item|
data = Repos.where(id: item.to_i).first
unless data.nil?
RepocRecips.insert(repo_id: data[:id], recip_id: id)
end
end
end
error_data
else
"Рецепт с таким именем #{filepath_san} не существует"
end
end
end
def get_rcp_info_by_id(rcpi_id)
info = Recips[rcpi_id.to_i]
gits = RepocRecips.where(recip_id: info[:id])
info[:repos_list] = gits.map { |item| item[:repo_id].to_s }
info
end
def delete_rcp(id)
RepocRecips.where(recip_id: id.to_i).delete
Recips.where(id: id.to_i).delete
end
def proj_list
Projects.order(:id).all
end
def proj_create(proj_name, proj_descr)
@error = nil
data = Projects.where(projname: proj_name).first
if data.nil?
id = Projects.insert(projname: proj_name, descr: proj_descr, public: 1)
@last_id = id
else
@error = "Данный проект уже существует"
end
@error
end
2 months ago
end