Class: Source::FilesFromDirectoryProvider

Inherits:
FilesProvider show all
Defined in:
lib/gpm/source/files_providers/files_from_directory_provider.rb

Direct Known Subclasses

FilesFromBundlerDirectoryProvider

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FilesProvider

#files

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

#directoryObject (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_provideObject (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_contentsObject



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