Class: DocRepo::GithubFile
- Inherits:
-
Object
- Object
- DocRepo::GithubFile
- Defined in:
- lib/doc_repo/github_file.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#org ⇒ Object
readonly
Returns the value of attribute org.
-
#raw_url ⇒ Object
(also: #redirect_url)
readonly
Returns the value of attribute raw_url.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(file, org: DocRepo.configuration.org, repo: DocRepo.configuration.repo, branch: DocRepo.configuration.branch) ⇒ GithubFile
constructor
A new instance of GithubFile.
- #read_remote_file ⇒ Object
- #url(file) ⇒ Object
Constructor Details
#initialize(file, org: DocRepo.configuration.org, repo: DocRepo.configuration.repo, branch: DocRepo.configuration.branch) ⇒ GithubFile
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/doc_repo/github_file.rb', line 7 def initialize(file, org: DocRepo.configuration.org, repo: DocRepo.configuration.repo, branch: DocRepo.configuration.branch) @file = file @org = org @repo = repo @branch = branch @raw_url = url(file) end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def branch @branch end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def file @file end |
#org ⇒ Object (readonly)
Returns the value of attribute org.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def org @org end |
#raw_url ⇒ Object (readonly) Also known as: redirect_url
Returns the value of attribute raw_url.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def raw_url @raw_url end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def repo @repo end |
Instance Method Details
#headers ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/doc_repo/github_file.rb', line 26 def headers hash = { "Accept" => "application/vnd.github.v3.raw", "User-Agent" => "RadiusNetworks-ProximityKit", } if ENV["GITHUB_TOKEN"] hash["Authorization"] = "token #{ENV["GITHUB_TOKEN"]}" end hash end |
#read_remote_file ⇒ Object
20 21 22 23 24 |
# File 'lib/doc_repo/github_file.rb', line 20 def read_remote_file open(raw_url, headers).read rescue OpenURI::HTTPError => http_error raise DocRepo::NotFound.new(base: http_error) end |
#url(file) ⇒ Object
39 40 41 |
# File 'lib/doc_repo/github_file.rb', line 39 def url(file) "https://raw.githubusercontent.com/#{org}/#{repo}/#{branch}/docs/#{file}" end |