Class: Source::FilesFromDirectoryProvider
- Inherits:
-
FilesProvider
- Object
- FilesProvider
- Source::FilesFromDirectoryProvider
- Defined in:
- lib/gpm/source/files_providers/files_from_directory_provider.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#files_to_provide ⇒ Object
readonly
Returns the value of attribute files_to_provide.
Class Method Summary collapse
-
.create_from_directory(directory = ".", base_directory = nil) ⇒ Object
This is a factory method that constructs a FilesFromDirectoryProvider that will provide all files below directory but strip their paths such that they appear as relative to the base_directory.
- .create_from_glob(directory = nil, glob = '**/*', base_directory = nil) ⇒ Object
Instance Method Summary collapse
- #file_contents ⇒ Object
-
#initialize(directory, files_to_provide) ⇒ FilesFromDirectoryProvider
constructor
A new instance of FilesFromDirectoryProvider.
Methods inherited from FilesProvider
Constructor Details
#initialize(directory, files_to_provide) ⇒ FilesFromDirectoryProvider
Returns a new instance of FilesFromDirectoryProvider.
22 23 24 25 |
# File 'lib/gpm/source/files_providers/files_from_directory_provider.rb', line 22 def initialize(directory,files_to_provide) @directory = directory @files_to_provide = files_to_provide end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
20 21 22 |
# File 'lib/gpm/source/files_providers/files_from_directory_provider.rb', line 20 def directory @directory end |
#files_to_provide ⇒ Object (readonly)
Returns the value of attribute files_to_provide.
20 21 22 |
# File 'lib/gpm/source/files_providers/files_from_directory_provider.rb', line 20 def files_to_provide @files_to_provide end |
Class Method Details
.create_from_directory(directory = ".", base_directory = nil) ⇒ Object
This is a factory method that constructs a FilesFromDirectoryProvider that will provide all files below directory but strip their paths such that they appear as relative to the base_directory
8 9 10 |
# File 'lib/gpm/source/files_providers/files_from_directory_provider.rb', line 8 def self.create_from_directory(directory=".", base_directory=nil) return create_from_glob(directory, '**/*', base_directory) end |
.create_from_glob(directory = nil, glob = '**/*', base_directory = nil) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/gpm/source/files_providers/files_from_directory_provider.rb', line 12 def self.create_from_glob(directory=nil, glob='**/*', base_directory=nil) directory ||= '.' base_directory ||= directory base_path = Pathname.new(base_directory) files = Dir[File.join(directory, glob)].collect {|file| Pathname.new(file).relative_path_from(base_path).to_s } new(base_directory, files) end |
Instance Method Details
#file_contents ⇒ Object
27 28 29 |
# File 'lib/gpm/source/files_providers/files_from_directory_provider.rb', line 27 def file_contents read_file_contents files_to_provide, directory end |