Class: KExt::Github::Printer

Inherits:
Object
  • Object
show all
Extended by:
KLog::Logging
Defined in:
lib/k_ext/github/printer.rb

Overview

Print formatted log for GitHub data such as repositories

Class Method Summary collapse

Class Method Details

.hook(hook) ⇒ Object



108
109
110
111
112
113
114
# 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) ⇒ Object



116
117
118
119
120
121
122
123
124
# 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) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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) ⇒ Object



99
100
101
102
103
104
105
106
# 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') ⇒ Object


Print Hooks




72
73
74
75
76
77
78
79
80
81
82
83
84
# 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') ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# 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) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# 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') ⇒ Object


Print Repositories




13
14
15
16
17
18
19
20
21
22
23
24
25
# 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') ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Object



50
51
52
53
54
55
# 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) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# 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) ⇒ Object



41
42
43
44
45
46
47
48
# 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