class SiteConstruct include Mongoid::Document include Mongoid::Timestamps def self.server_types SiteServer.all.map{|s| s.server_name} end SITE_TYPES = ["School","Gravity"] field :server_type field :site_name field :domain_name field :nginx_file field :db_name field :port, type: String, :default => "80" field :path field :site_type field :school_name field :user_id field :constructed, type: Boolean, :default => false field :status, type: String, :default => "" field :infos, type: Array, :default => [] field :hidden, type: Boolean, :default => false field :copy_id field :cert_ver_added_text field :cert_ver_file_content field :cert_ver_location_path after_initialize do |record| if record.status.nil? record.status = "" record.save end if record.infos.nil? record.infos = [] record.save end if record.nginx_file.nil? record.nginx_file = "/etc/nginx/orbit_sites/"+record.site_name.to_s record.save end if record.path.nil? dir_path = ((record.site_type == "School" && !record.school_name.blank?) ? "school_sites/#{record.school_name}" : "orbit_sites") record.path = "/home/rulingcom/#{dir_path}" end end def get_site_name return self.site_name.gsub(" ","\\ ") end def get_domain_name scheme = "" extra_port = "" if self.port == "443" scheme = "https://" else scheme = "http://" if self.port != "80" extra_port = ":#{self.port}" end end return (scheme + self.domain_name + extra_port) end def site_server SiteServer.where(server_name: self.server_type).first end end