Class: Fetchers::Local
- Inherits:
-
Object
- Object
- Fetchers::Local
- Defined in:
- lib/fetchers/local.rb
Class Method Summary collapse
Instance Method Summary collapse
- #archive_path ⇒ Object
- #cache_key ⇒ Object
- #fetch(_path) ⇒ Object
-
#initialize(target) ⇒ Local
constructor
A new instance of Local.
- #resolved_source ⇒ Object
- #sha256 ⇒ Object
- #writable? ⇒ Boolean
Constructor Details
#initialize(target) ⇒ Local
Returns a new instance of Local.
48 49 50 |
# File 'lib/fetchers/local.rb', line 48 def initialize(target) @target = target end |
Class Method Details
.resolve(target) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fetchers/local.rb', line 12 def self.resolve(target) local_path = if target.is_a?(String) resolve_from_string(target) elsif target.is_a?(Hash) resolve_from_hash(target) end if local_path new(local_path) end end |
.resolve_from_hash(target) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/fetchers/local.rb', line 24 def self.resolve_from_hash(target) if target.key?(:path) local_path = target[:path] if target.key?(:cwd) local_path = File.(local_path, target[:cwd]) end local_path end end |
.resolve_from_string(target) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fetchers/local.rb', line 34 def self.resolve_from_string(target) # Support "urls" in the form of file:// if target.start_with?('file://') target = target.gsub(%r{^file://}, '') else # support for windows paths target = target.tr('\\', '/') end if File.exist?(target) target end end |
Instance Method Details
#archive_path ⇒ Object
56 57 58 |
# File 'lib/fetchers/local.rb', line 56 def archive_path @target end |
#cache_key ⇒ Object
64 65 66 |
# File 'lib/fetchers/local.rb', line 64 def cache_key sha256.to_s end |
#fetch(_path) ⇒ Object
52 53 54 |
# File 'lib/fetchers/local.rb', line 52 def fetch(_path) archive_path end |
#resolved_source ⇒ Object
74 75 76 77 78 |
# File 'lib/fetchers/local.rb', line 74 def resolved_source h = { path: @target } h[:sha256] = sha256 if sha256 h end |
#sha256 ⇒ Object
68 69 70 71 72 |
# File 'lib/fetchers/local.rb', line 68 def sha256 return nil if File.directory?(@target) @archive_shasum ||= OpenSSL::Digest::SHA256.digest(File.read(@target)).unpack('H*')[0] end |
#writable? ⇒ Boolean
60 61 62 |
# File 'lib/fetchers/local.rb', line 60 def writable? File.directory?(@target) end |