Sha256: e98545588f84b55c1a9cbe057a92c91adbfc36b58d3ef980d2c2f903a0beec50
Contents?: true
Size: 880 Bytes
Versions: 5
Compression:
Stored size: 880 Bytes
Contents
# frozen_string_literal: true module Spandx class Database attr_reader :path, :url def initialize(url:) @url = url @path = path_for(url) end def update! dotgit? ? pull! : clone! end def read(file) full_path = File.join(path, file) IO.read(full_path) if File.exist?(full_path) end private def path_for(url) uri = URI.parse(url) name = uri.path.gsub(/\.git$/, '') File.expand_path(File.join(Dir.home, '.local', 'share', name)) end def dotgit? File.directory?(File.join(path, '.git')) end def clone! system('git', 'clone', '--quiet', url, path) end def pull! within do system('git', 'pull', '--no-rebase', '--quiet', 'origin', 'master') end end def within Dir.chdir(path) do yield end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
spandx-0.5.0 | lib/spandx/database.rb |
spandx-0.4.1 | lib/spandx/database.rb |
spandx-0.4.0 | lib/spandx/database.rb |
spandx-0.3.0 | lib/spandx/database.rb |
spandx-0.2.0 | lib/spandx/database.rb |