Class: D2::Helpers::Git::LocalRepo
- Inherits:
-
Object
- Object
- D2::Helpers::Git::LocalRepo
- Defined in:
- lib/d2/helpers/git/local_repo.rb
Constant Summary collapse
- UndeterminedError =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(fragment) ⇒ LocalRepo
constructor
A new instance of LocalRepo.
-
#org_or_user ⇒ String
The organization or user that owns the repo Defaults to DEFAULT_ORG_OR_USER in the case none is specified.
- #path_on_disk ⇒ Object
-
#provider ⇒ String
The provider for the url, aka the git server This will usually be one of: github.com, bitbucket.org, or gitlab.com Defaults to the default provider set in the config in the case none is specified.
-
#repo_name ⇒ String
The repository name.
-
#url(type:) ⇒ String
Provides a full git URL in SSH or HTTPS format.
Constructor Details
#initialize(fragment) ⇒ LocalRepo
Returns a new instance of LocalRepo
17 18 19 |
# File 'lib/d2/helpers/git/local_repo.rb', line 17 def initialize(fragment) @fragment = fragment.gsub(/\.git$/, '') end |
Instance Method Details
#org_or_user ⇒ String
The organization or user that owns the repo Defaults to DEFAULT_ORG_OR_USER in the case none is specified
43 44 45 46 47 48 49 50 51 |
# File 'lib/d2/helpers/git/local_repo.rb', line 43 def org_or_user split_path = path.split('/', 2) case split_path.size when 1 D2::Config.get('git', 'default_owner') when 2 split_path.first end end |
#path_on_disk ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/d2/helpers/git/local_repo.rb', line 78 def path_on_disk File.( File.join( D2::Config.get('src_path', 'default'), provider, org_or_user, repo_name ) ) end |
#provider ⇒ String
The provider for the url, aka the git server This will usually be one of: github.com, bitbucket.org, or gitlab.com Defaults to the default provider set in the config in the case none is specified
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/d2/helpers/git/local_repo.rb', line 27 def provider case fragement_type when TYPES[:ssh], TYPES[:https] parsed_uri.host when TYPES[:org_repo], TYPES[:repo] D2::Config.get('git', 'default_provider') when TYPES[:undetermined] raise UndeterminedError end end |
#repo_name ⇒ String
The repository name
57 58 59 |
# File 'lib/d2/helpers/git/local_repo.rb', line 57 def repo_name path.split('/', 2).last end |
#url(type:) ⇒ String
Provides a full git URL in SSH or HTTPS format
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/d2/helpers/git/local_repo.rb', line 67 def url(type:) case type when 'ssh' "git@#{provider}:#{org_or_user}/#{repo_name}.git" when 'https' "https://#{provider}/#{org_or_user}/#{repo_name}.git" else raise ArgumentError, "#{type} is not a supported type" end end |