class StatusPageRubyCli

Constants

PULL_SECONDS

Attributes

backup_data[R]
build_history_table[R]
build_log_table[R]
build_stats_table[R]
pull_statuses[R]
restore_data[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/status_page_ruby_cli.rb, line 4
def initialize(*args)
  super(*args)
  data_file_path = File.join(ENV['HOME'], '.status_page_ruby_data.csv')
  create_data_file_if_needed(data_file_path)
  storage = StatusPageRuby::Storage.new(data_file_path)
  repository = StatusPageRuby::Repositories::Status.new(storage)
  setup_services(repository)
end

Public Instance Methods

backup() click to toggle source
# File lib/status_page_ruby_cli.rb, line 42
def backup
  backup_data.call(options[:path])
end
history() click to toggle source
# File lib/status_page_ruby_cli.rb, line 30
def history
  puts build_history_table.call(options[:service])
end
live() click to toggle source
# File lib/status_page_ruby_cli.rb, line 21
def live
  loop do
    puts build_log_table.call(pull_statuses.call)
    sleep PULL_SECONDS
  end
end
pull() click to toggle source
# File lib/status_page_ruby_cli.rb, line 15
def pull
  records = pull_statuses.call
  puts build_log_table.call(records) if options[:log]
end
restore() click to toggle source
# File lib/status_page_ruby_cli.rb, line 48
def restore
  restore_data.call(options[:path])
end
stats() click to toggle source
# File lib/status_page_ruby_cli.rb, line 36
def stats
  puts build_stats_table.call(options[:service])
end

Private Instance Methods

create_data_file_if_needed(path) click to toggle source
# File lib/status_page_ruby_cli.rb, line 70
def create_data_file_if_needed(path)
  return if File.exist?(path)

  FileUtils.mkpath(File.dirname(path))
  FileUtils.touch(path)
end
setup_services(status_repository) click to toggle source
# File lib/status_page_ruby_cli.rb, line 61
def setup_services(status_repository)
  @build_history_table = StatusPageRuby::Services::BuildHistoryTable.new(status_repository)
  @build_log_table = StatusPageRuby::Services::BuildLogTable.new
  @build_stats_table = StatusPageRuby::Services::BuildStatsTable.new(status_repository)
  @pull_statuses = StatusPageRuby::Services::PullStatuses.new(status_repository)
  @backup_data = StatusPageRuby::Services::BackupData.new(status_repository.storage)
  @restore_data = StatusPageRuby::Services::RestoreData.new(status_repository.storage)
end