# encoding: utf-8 class Service < ActiveRecord::Base attr_accessor :current_url # validates :title, :presence => true # validates :body, :presence => true belongs_to :machine belongs_to :service_type acts_as_list scope: :service_type # scope :published, -> { order("created_at DESC") } def tailscale_ip_url if machine.tailscale_ip.present? url = "http://#{machine.tailscale_ip}:#{port}" if url_path.present? url.concat(url_path) end url end end def local_domain_url url = "http://" if subdomain.present? url.concat("#{subdomain}.") end url.concat(machine.local_domain) if url_path.present? url.concat(url_path) end url end def local_ip_url url = "http://#{machine.local_ip}:#{port}" if url_path.present? url.concat(url_path) end url end def set_current_url(url_type) if url_type == 'tailscale' self.current_url = self.tailscale_ip_url elsif url_type == 'local_ip' self.current_url = self.local_ip_url else self.current_url = self.local_domain_url end end end