Class: Gisture::Repo
- Inherits:
-
Object
- Object
- Gisture::Repo
- Defined in:
- lib/gisture/repo.rb
Constant Summary collapse
- REPO_URL_REGEX =
/\A((http[s]?:\/\/)?github\.com\/)?([a-z0-9_\-\.]*)\/([a-z0-9_\-\.]*)\/?\Z/i
- FILE_URL_REGEX =
/\A((http[s]?:\/\/)?github\.com\/)?(([a-z0-9_\-\.]*)\/([a-z0-9_\-\.]*))(\/[a-z0-9_\-\.\/]+)\Z/i
Instance Attribute Summary collapse
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
- .file(path, strategy: nil) ⇒ Object
- .parse_file_url(file_url) ⇒ Object
- .parse_repo_url(repo_url) ⇒ Object
- .run!(path, strategy: nil, &block) ⇒ Object
Instance Method Summary collapse
- #file(path, strategy: nil) ⇒ Object
- #github ⇒ Object
- #repo ⇒ Object
- #run!(path, strategy: nil, &block) ⇒ Object
Instance Attribute Details
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
3 4 5 |
# File 'lib/gisture/repo.rb', line 3 def owner @owner end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
3 4 5 |
# File 'lib/gisture/repo.rb', line 3 def project @project end |
Class Method Details
.file(path, strategy: nil) ⇒ Object
8 9 10 11 |
# File 'lib/gisture/repo.rb', line 8 def file(path, strategy: nil) repo, file = parse_file_url(path) new(repo).file(file, strategy: strategy) end |
.parse_file_url(file_url) ⇒ Object
23 24 25 26 27 |
# File 'lib/gisture/repo.rb', line 23 def parse_file_url(file_url) matched = file_url.match(FILE_URL_REGEX) raise ArgumentError, "Invalid argument: '#{file_url}' is not a valid file path." if matched.nil? [matched[3], matched[6]] end |
.parse_repo_url(repo_url) ⇒ Object
17 18 19 20 21 |
# File 'lib/gisture/repo.rb', line 17 def parse_repo_url(repo_url) matched = repo_url.match(REPO_URL_REGEX) raise ArgumentError, "Invalid argument: '#{repo_url}' is not a valid repo URL." if matched.nil? [matched[3], matched[4]] end |
.run!(path, strategy: nil, &block) ⇒ Object
13 14 15 |
# File 'lib/gisture/repo.rb', line 13 def run!(path, strategy: nil, &block) file(path, strategy: strategy).run!(&block) end |
Instance Method Details
#file(path, strategy: nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/gisture/repo.rb', line 40 def file(path, strategy: nil) file = github.repos.contents.get(user: owner, repo: project, path: path).body file['filename'] = ::File.basename(file['path']) file['content'] = Base64.decode64(file['content']) Gisture::File.new(file, basename: "#{owner}-#{project}", strategy: strategy) end |
#github ⇒ Object
30 31 32 33 34 |
# File 'lib/gisture/repo.rb', line 30 def github @github ||= begin Github.new(github_config) end end |
#repo ⇒ Object
36 37 38 |
# File 'lib/gisture/repo.rb', line 36 def repo @repo ||= github.repos.get user: owner, repo: project end |
#run!(path, strategy: nil, &block) ⇒ Object
47 48 49 |
# File 'lib/gisture/repo.rb', line 47 def run!(path, strategy: nil, &block) file(path, strategy: strategy).run!(&block) end |