module NexClient::Commands::Domains
Constants
- DOMAINS_HEADERS
- DOMAINS_TITLE
Public Class Methods
create(args,opts)
click to toggle source
# File lib/nex_client/commands/domains.rb, line 26 def self.create(args,opts) domain_name,app_name = args app = NexClient::App.find(name: app_name).first app ||= NexClient::CubeInstance.find(name: app_name).first # Display error unless app error("Error! Could not find app: #{app_name}") return false end domain = NexClient::Domain.new(cname: domain_name) domain.relationships.attributes = { origin: { data: { type: app.type, id: app.id } } } domain.save # Display errors if any if domain.errors.any? display_record_errors(domain) return false end # Display domains self.display_domains(NexClient::Domain.includes(:origin).find(domain.id).first) end
destroy(args,opts)
click to toggle source
# File lib/nex_client/commands/domains.rb, line 51 def self.destroy(args,opts) name = args.first e = NexClient::Domain.find(cname: name).first # Display error unless e error("Error! Could not find domain: #{name}") return false end # Ask confirmation answer = ask("Enter the name of this domain to confirm: ") unless answer == e.cname error("Aborting deletion...") return false end e.destroy success("Successfully destroyed domain: #{name}") end
display_domains(list)
click to toggle source
# File lib/nex_client/commands/domains.rb, line 72 def self.display_domains(list) table = Terminal::Table.new title: DOMAINS_TITLE, headings: DOMAINS_HEADERS do |t| [list].flatten.compact.each do |e| t.add_row(self.format_record(e)) end end puts table puts "\n" end
format_origin(record)
click to toggle source
# File lib/nex_client/commands/domains.rb, line 92 def self.format_origin(record) return "-" unless record.origin record.origin.name end
format_record(record)
click to toggle source
# File lib/nex_client/commands/domains.rb, line 82 def self.format_record(record) origin = self.format_origin(record) [ record.id, record.cname, record.ssl_available, origin ] end
list(args,opts)
click to toggle source
# File lib/nex_client/commands/domains.rb, line 10 def self.list(args,opts) filters = {} filters[:'origin.name'] = args.first if args.first.present? # Create table list = NexClient::Domain.includes(:origin).where(filters).order('cname') self.display_domains(list) # Loop through results while (list.pages.links||{})['next'] return true if ask("Press enter for next page ('q' to quit)") =~ /q/ list = list.pages.next self.display_domains(list) end end