Class: Sourcerer::SourceType

Inherits:
Object
  • Object
show all
Defined in:
lib/sourcerer/source_type.rb

Direct Known Subclasses

Dir, Git, Zip

Defined Under Namespace

Classes: Dir, Git, Zip

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sourcerer) ⇒ SourceType

Returns a new instance of SourceType.


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sourcerer/source_type.rb', line 7

def initialize sourcerer
  @source = sourcerer.source
  @destination = sourcerer.destination
  @options = sourcerer.options

  # runs source type specific `move` method to get files from the source to the destination
  move

  # append subdirectory if it exists
  if @options[:subdirectory]
    @destination = File.join @destination, @options[:subdirectory]
  end
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination


2
3
4
# File 'lib/sourcerer/source_type.rb', line 2

def destination
  @destination
end

#sourceObject (readonly)

Returns the value of attribute source


2
3
4
# File 'lib/sourcerer/source_type.rb', line 2

def source
  @source
end

Instance Method Details

#files(glob = :all, relative = false) ⇒ Object

Return an array of file paths that match the provided glob


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sourcerer/source_type.rb', line 23

def files glob = :all, relative = false
  glob = case glob
  when :all
    '**/{.[^\.]*,*}'
  when :hidden
    '**/.*}'
  else
    glob
  end

  files = ::Dir.glob(File.join(@destination, glob)).select do |file|
    File.file? file
  end

  if relative
    base_path = Pathname.new @destination
    files = files.collect do |file|
      Pathname.new(file).relative_path_from(base_path).to_s
    end
  end

  return files
end