Class: LikeAVirgin::FileMap

Inherits:
Object
  • Object
show all
Defined in:
lib/like_a_virgin/file_map.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, files) ⇒ FileMap

Returns a new instance of FileMap.



3
4
5
6
7
# File 'lib/like_a_virgin/file_map.rb', line 3

def initialize(root, files)
  @root    = root
  @files   = files
  @mapping = {}
end

Instance Method Details

#[]=(source, depends) ⇒ Object



32
33
34
35
# File 'lib/like_a_virgin/file_map.rb', line 32

def []=(source, depends)
  @mapping[source] ||= []
  @mapping[source]  << depends
end

#clearObject



9
10
11
12
# File 'lib/like_a_virgin/file_map.rb', line 9

def clear
  @mapping = {}
  @pattern = nil
end

#file?(file) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/like_a_virgin/file_map.rb', line 37

def file?(file)
  FileTest.exist?(file) and FileTest.file?(file)
end

#matches(pattern) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/like_a_virgin/file_map.rb', line 22

def matches(pattern)
  if block_given?
    @files.grep(pattern) do |file|
      yield self, file
    end
  else
    @files.grep(pattern)
  end
end

#patternObject



14
15
16
17
18
19
20
# File 'lib/like_a_virgin/file_map.rb', line 14

def pattern
  @pattern ||= @mapping.inject({}) do |result, (source, depends)|
    depend = depends.flatten.select{ |f| file? f }
    result[source] = depend unless depend.empty?
    result
  end
end