Class: Fetchers::Local
- Inherits:
-
Object
- Object
- Fetchers::Local
- Defined in:
- lib/fetchers/local.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(target) ⇒ Local
constructor
A new instance of Local.
- #read(file) ⇒ Object
Constructor Details
#initialize(target) ⇒ Local
Returns a new instance of Local.
30 31 32 33 34 35 36 37 |
# File 'lib/fetchers/local.rb', line 30 def initialize(target) @target = target if File.file?(target) @files = [target] else @files = Dir[File.join(target, '**', '*')] end end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
10 11 12 |
# File 'lib/fetchers/local.rb', line 10 def files @files end |
Class Method Details
.resolve(target) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fetchers/local.rb', line 12 def self.resolve(target) return nil unless target.is_a?(String) # 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) nil else new(target) end end |
Instance Method Details
#read(file) ⇒ Object
39 40 41 42 43 |
# File 'lib/fetchers/local.rb', line 39 def read(file) return nil unless files.include?(file) return nil unless File.file?(file) File.read(file) end |