class KExt::Github::Printer

Print formatted log for GitHub data such as repositories

Public Class Methods

hook(hook) click to toggle source
# File lib/k_ext/github/printer.rb, line 108
def self.hook(hook)
  hook_key_values(hook).each do |key_value|
    log.kv key_value.key, key_value.vale
  end

  log.line
end
hook_detailed(hook) click to toggle source
# File lib/k_ext/github/printer.rb, line 116
def self.hook_detailed(hook)
  hook_key_values(hook).each do |key_value|
    log.kv key_value.key, key_value.vale
  end

  # Print Relations

  log.line
end
hook_key_values(hook) click to toggle source
# File lib/k_ext/github/printer.rb, line 142
def self.hook_key_values(hook)
  {
    type: hook.type,
    id: hook.id,
    name: hook.name,
    active: hook.active,
    events: hook.events,
    config: hook.config,
    updated_at: hook.updated_at,
    created_at: hook.created_at,
    url: hook.url,
    test_url: hook.test_url,
    ping_url: hook.ping_url,
    last_response: hook.last_response
  }
end
hook_with_format(repo, format) click to toggle source
# File lib/k_ext/github/printer.rb, line 99
def self.hook_with_format(repo, format)
  case format
  when 'detailed'
    hook_detailed(repo)
  else
    hook(repo)
  end
end
hooks(rows = nil, format = 'default') click to toggle source

Print Hooks


# File lib/k_ext/github/printer.rb, line 72
def self.hooks(rows = nil, format = 'default')
  log.block 'Hooks'

  if rows.nil?
    Hook.all.each do |_r|
      hook_with_format(repo, format)
    end
  else
    rows.each do |_r|
      hook_with_format(repo, format)
    end
  end
end
hooks_as_table(rows = nil, format = 'default') click to toggle source
# File lib/k_ext/github/printer.rb, line 86
def self.hooks_as_table(rows = nil, format = 'default')
  log.block 'Hooks'

  rows = Hook.all if rows.nil?

  case format
  when 'detailed'
    tp rows, :type, :id, :name, :active, :events, :config, :updated_at, :created_at, :url, :test_url, :ping_url, :last_response
  else
    tp rows, :type, :id, :name, :active, :url, :config
  end
end
repo_key_values(repo) click to toggle source
# File lib/k_ext/github/printer.rb, line 126
def self.repo_key_values(repo)
  {
    id: repo.id,
    node_id: repo.node_id,
    name: repo.name,
    full_name: repo.full_name,
    private: repo.private,
    description: repo.description,
    url: repo.url,
    created_at: repo.created_at,
    updated_at: repo.updated_at,
    pushed_at: repo.pushed_at,
    git_url: repo.git_url
  }
end
repositories(rows = nil, format = 'default') click to toggle source

Print Repositories


# File lib/k_ext/github/printer.rb, line 13
def self.repositories(rows = nil, format = 'default')
  log.block 'Repositories'

  if rows.nil?
    Repository.all.each do |_r|
      repository_with_format(repo, format)
    end
  else
    rows.each do |_r|
      repository_with_format(repo, format)
    end
  end
end
repositories_as_table(rows = nil, format = 'default') click to toggle source
# File lib/k_ext/github/printer.rb, line 27
def self.repositories_as_table(rows = nil, format = 'default')
  log.block 'Repositories'

  rows = Repository.all if rows.nil?

  case format
  when 'detailed'
    # tp rows
    tp rows, :id, :node_id, :name, :full_name, :private, :description, :url, 'owner.login', :created_at, :updated_at, :pushed_at, :git_url
  else
    tp rows, :id, :name, :git_url, :full_name, :private, :description, :url, 'owner.login'
  end
end
repository(repo) click to toggle source
# File lib/k_ext/github/printer.rb, line 50
def self.repository(repo)
  data = repo_key_values(repo)

  log.kv_hash(data)
  log.line
end
repository_detailed(repo) click to toggle source
# File lib/k_ext/github/printer.rb, line 57
def self.repository_detailed(repo)
  data = repo_key_values(repo)

  log.kv_hash(data)
  log.line

  # Print Relations

  log.line
end
repository_with_format(repo, format) click to toggle source
# File lib/k_ext/github/printer.rb, line 41
def self.repository_with_format(repo, format)
  case format
  when 'detailed'
    repository_detailed(repo)
  else
    repository(repo)
  end
end