Class: Gemkeeper::GitRepository
- Inherits:
-
Object
- Object
- Gemkeeper::GitRepository
- Defined in:
- lib/gemkeeper/git_repository.rb
Overview
Centralizes safe ref validation; prevents command injection via untrusted version strings.
Constant Summary collapse
- SAFE_REF_PATTERN =
/\A[a-zA-Z0-9._-]+\z/
Instance Attribute Summary collapse
-
#local_path ⇒ Object
readonly
Returns the value of attribute local_path.
-
#repo_url ⇒ Object
readonly
Returns the value of attribute repo_url.
Instance Method Summary collapse
- #checkout_version(version) ⇒ Object
- #clone_or_pull ⇒ Object
- #current_version ⇒ Object
- #find_gemspec ⇒ Object
-
#initialize(repo_url, local_path) ⇒ GitRepository
constructor
A new instance of GitRepository.
Constructor Details
#initialize(repo_url, local_path) ⇒ GitRepository
Returns a new instance of GitRepository.
11 12 13 14 |
# File 'lib/gemkeeper/git_repository.rb', line 11 def initialize(repo_url, local_path) @repo_url = repo_url @local_path = local_path end |
Instance Attribute Details
#local_path ⇒ Object (readonly)
Returns the value of attribute local_path.
9 10 11 |
# File 'lib/gemkeeper/git_repository.rb', line 9 def local_path @local_path end |
#repo_url ⇒ Object (readonly)
Returns the value of attribute repo_url.
9 10 11 |
# File 'lib/gemkeeper/git_repository.rb', line 9 def repo_url @repo_url end |
Instance Method Details
#checkout_version(version) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/gemkeeper/git_repository.rb', line 26 def checkout_version(version) if version == "latest" checkout_trunk else checkout_tag(version) end end |
#clone_or_pull ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/gemkeeper/git_repository.rb', line 16 def clone_or_pull if File.directory?(File.join(@local_path, ".git")) pull else clone end end |
#current_version ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/gemkeeper/git_repository.rb', line 34 def current_version gemspec_path = find_gemspec return nil unless gemspec_path content = File.read(gemspec_path) extract_version_from_content(content) || version_from_requires(content, File.dirname(gemspec_path)) || version_from_version_files end |
#find_gemspec ⇒ Object
44 45 46 |
# File 'lib/gemkeeper/git_repository.rb', line 44 def find_gemspec Dir.glob(File.join(@local_path, "*.gemspec")).first end |