Class: LikeAVirgin::FileMap
- Inherits:
-
Object
- Object
- LikeAVirgin::FileMap
- Defined in:
- lib/like_a_virgin/file_map.rb
Instance Method Summary collapse
- #[]=(source, depends) ⇒ Object
- #clear ⇒ Object
- #file?(file) ⇒ Boolean
-
#initialize(root, files) ⇒ FileMap
constructor
A new instance of FileMap.
- #matches(pattern) ⇒ Object
- #pattern ⇒ Object
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 |
#clear ⇒ Object
9 10 11 12 |
# File 'lib/like_a_virgin/file_map.rb', line 9 def clear @mapping = {} @pattern = nil end |
#file?(file) ⇒ 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 |
#pattern ⇒ Object
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 |