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.
-
#elm_version_of(ref) ⇒ Array
Returns the supported Elm version the given ref.
-
#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, should_update, only_update) ⇒ 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 |
#elm_version_of(ref) ⇒ Array
Returns the supported Elm version the given ref.
77 78 79 80 81 |
# File 'lib/elm_install/git_source.rb', line 77 def elm_version_of(ref) @@elm_versions ||= {} @@elm_versions[url] ||= {} @@elm_versions[url][ref] ||= identifier.elm_version(fetch(ref)) 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
149 150 151 152 153 154 155 156 |
# File 'lib/elm_install/git_source.rb', line 149 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
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/elm_install/git_source.rb', line 118 def matching_versions(constraints, elm_version) repository .versions .select do |version| elm_version_of(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
162 163 164 165 166 167 168 169 |
# File 'lib/elm_install/git_source.rb', line 162 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
141 142 143 |
# File 'lib/elm_install/git_source.rb', line 141 def path File.join([:cache_directory].to_s, host, package_name) end |
#repository ⇒ Repository
Returns the local repository
175 176 177 |
# File 'lib/elm_install/git_source.rb', line 175 def repository @repository ||= Repository.of url, path end |
#to_log ⇒ String
Returns the log format
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/elm_install/git_source.rb', line 183 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
133 134 135 |
# File 'lib/elm_install/git_source.rb', line 133 def url @uri.to_s end |
#versions(constraints, elm_version, should_update, only_update) ⇒ Array
Returns the available versions for a repository
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/elm_install/git_source.rb', line 93 def versions(constraints, elm_version, should_update, only_update) if repository.cloned? && !repository.fetched && should_update && (!only_update || only_update == package_name) # 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 |