Class: RepoAnalyzer::ProjectDataBridge

Inherits:
Object
  • Object
show all
Defined in:
app/values/repo_analyzer/project_data_bridge.rb

Constant Summary collapse

EXCLUDED_FILE_NAMES =
%w{. .. .keep .gitkeep}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_name, project_path = Rails.root.to_s) ⇒ ProjectDataBridge

Returns a new instance of ProjectDataBridge.



7
8
9
10
# File 'app/values/repo_analyzer/project_data_bridge.rb', line 7

def initialize(repo_name, project_path = Rails.root.to_s)
  @repo_name = repo_name
  @project_path = project_path
end

Instance Attribute Details

#project_pathObject (readonly)

Returns the value of attribute project_path.



5
6
7
# File 'app/values/repo_analyzer/project_data_bridge.rb', line 5

def project_path
  @project_path
end

Instance Method Details

#commits(options = {}) ⇒ Object



30
31
32
# File 'app/values/repo_analyzer/project_data_bridge.rb', line 30

def commits(options = {})
  github_client.commits(repo_name, **options)
end

#contributorsObject



34
35
36
# File 'app/values/repo_analyzer/project_data_bridge.rb', line 34

def contributors
  github_client.contributors(repo_name)
end

#dir_files(dir_path) ⇒ Object



22
23
24
25
26
27
28
# File 'app/values/repo_analyzer/project_data_bridge.rb', line 22

def dir_files(dir_path)
  Dir.glob("#{project_path}/#{dir_path}/**/*").reject do |file_name|
    EXCLUDED_FILE_NAMES.include?(file_name)
  end
rescue Errno::ENOENT
  []
end

#file_content(file_path) ⇒ Object



16
17
18
19
20
# File 'app/values/repo_analyzer/project_data_bridge.rb', line 16

def file_content(file_path)
  return unless file_exist?(file_path)

  File.open("#{project_path}/#{file_path}").read
end

#file_exist?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/values/repo_analyzer/project_data_bridge.rb', line 12

def file_exist?(file_path)
  File.exist?("#{project_path}/#{file_path}")
end