Class: ElmInstall::GitSource
- Defined in:
- lib/elm_install/git_source.rb
Overview
Git Source
Instance Attribute Summary collapse
-
#branch ⇒ Branch
readonly
The branch.
-
#uri ⇒ Uri
readonly
The uri.
Attributes inherited from Source
Instance Method Summary collapse
-
#copy_to(version, directory) ⇒ Object
Copies the version into the given directory.
-
#fetch(version) ⇒ Dir
Downloads the version into a temporary directory.
-
#host ⇒ String
Returns the host for the repository.
-
#initialize(uri, branch) ⇒ GitSource
constructor
Initializes a git source by URI and branch.
-
#matching_versions(constraints, elm_version) ⇒ Array
Returns the matchign versions for a repository for the given constraints.
-
#package_name ⇒ String
Returns the package name for the repository.
-
#path ⇒ String
Returns the temporary path for the repository.
-
#repository ⇒ Repository
Returns the local repository.
-
#to_log ⇒ String
Returns the log format.
-
#url ⇒ String
Returns the url for the repository.
-
#versions(constraints, elm_version) ⇒ Array
Returns the available versions for a repository.
Constructor Details
#initialize(uri, branch) ⇒ GitSource
Initializes a git source by URI and branch
17 18 19 20 21 |
# File 'lib/elm_install/git_source.rb', line 17 def initialize(uri, branch) @branch = branch @uri = uri self end |
Instance Attribute Details
#branch ⇒ Branch (readonly)
Returns The branch.
8 9 10 |
# File 'lib/elm_install/git_source.rb', line 8 def branch @branch end |
#uri ⇒ Uri (readonly)
Returns The uri.
5 6 7 |
# File 'lib/elm_install/git_source.rb', line 5 def uri @uri end |
Instance Method Details
#copy_to(version, directory) ⇒ Object
Copies the version into the given directory
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/elm_install/git_source.rb', line 54 def copy_to(version, directory) # Delete the directory to make sure no pervious version remains if # we are using a branch or symlink if using Dir. FileUtils.rm_rf(directory) if directory.exist? # Create directory if not exists FileUtils.mkdir_p directory # Copy hole repository FileUtils.cp_r("#{fetch(version).path}/.", directory) # Remove .git directory FileUtils.rm_rf(File.join(directory, '.git')) nil end |
#fetch(version) ⇒ Dir
Downloads the version into a temporary directory
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/elm_install/git_source.rb', line 29 def fetch(version) # Get the reference from the branch ref = case @branch when Branch::Just @branch.ref when Branch::Nothing case version when String version else version.to_simple end end repository.checkout ref end |
#host ⇒ String
Returns the host for the repository
131 132 133 134 135 136 137 138 |
# File 'lib/elm_install/git_source.rb', line 131 def host case @uri when Uri::Github 'github.com' else @uri.uri.host end end |
#matching_versions(constraints, elm_version) ⇒ Array
Returns the matchign versions for a repository for the given constraints
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/elm_install/git_source.rb', line 100 def matching_versions(constraints, elm_version) repository .versions .select do |version| identifier.elm_version(fetch(version.to_s)) == elm_version && constraints.all? { |constraint| constraint.satisfies?(version) } end .sort .reverse end |
#package_name ⇒ String
Returns the package name for the repository
144 145 146 147 148 149 150 151 |
# File 'lib/elm_install/git_source.rb', line 144 def package_name case @uri when Uri::Github @uri.name else @uri.uri.path.sub(%r{^/}, '') end end |
#path ⇒ String
Returns the temporary path for the repository
123 124 125 |
# File 'lib/elm_install/git_source.rb', line 123 def path File.join([:cache_directory].to_s, host, package_name) end |
#repository ⇒ Repository
Returns the local repository
157 158 159 |
# File 'lib/elm_install/git_source.rb', line 157 def repository @repository ||= Repository.new url, path end |
#to_log ⇒ String
Returns the log format
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/elm_install/git_source.rb', line 165 def to_log case @uri when Uri::Ssh, Uri::Http case @branch when Branch::Just "#{url} at #{@branch.ref}" else # NOTE: Cannot happen # :nocov: url # :nocov: end else url end end |
#url ⇒ String
Returns the url for the repository
115 116 117 |
# File 'lib/elm_install/git_source.rb', line 115 def url @uri.to_s end |
#versions(constraints, elm_version) ⇒ Array
Returns the available versions for a repository
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/elm_install/git_source.rb', line 78 def versions(constraints, elm_version) if repository.cloned? && !repository.fetched? # Get updates from upstream Logger.arrow "Getting updates for: #{package_name.bold}" repository.fetch end case @branch when Branch::Just [identifier.version(fetch(@branch.ref))] when Branch::Nothing matching_versions constraints, elm_version end end |