Module: OnlyofficeGithubHelper::FileList
- Included in:
- GithubClient
- Defined in:
- lib/onlyoffice_github_helper/github_client/file_list.rb
Overview
Module for working with file list
Instance Method Summary collapse
-
#file_list(repo, refs: 'master') ⇒ Array<String>
Get file list in repo.
-
#file_tree(repo, refs: 'master') ⇒ Hash
Get file tree in repo.
-
#parse_tree(list, path: '') ⇒ Hash
Parse file tree.
Instance Method Details
#file_list(repo, refs: 'master') ⇒ Array<String>
Get file list in repo
10 11 12 13 14 |
# File 'lib/onlyoffice_github_helper/github_client/file_list.rb', line 10 def file_list(repo, refs: 'master') Octokit.tree(repo, refs, recursive: true).tree .reject { |elem| elem.type == 'tree' } .map(&:path) end |
#file_tree(repo, refs: 'master') ⇒ Hash
Get file tree in repo
20 21 22 23 |
# File 'lib/onlyoffice_github_helper/github_client/file_list.rb', line 20 def file_tree(repo, refs: 'master') list = file_list(repo, refs: refs) parse_tree(list) end |
#parse_tree(list, path: '') ⇒ Hash
Parse file tree
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/onlyoffice_github_helper/github_client/file_list.rb', line 29 def parse_tree(list, path: '') root_tree = { name: path } root_tree[:children] = [] childs = tree_childs(list) childs[:dirs].each do |child_item| sub_files = subdir_content(list, child_item) root_tree[:children] << parse_tree(sub_files, path: child_item) end root_tree[:children] << childs[:files] root_tree[:children].flatten! root_tree end |