Method: PathList::Patterns#initialize
- Defined in:
- lib/path_list/patterns.rb
#initialize(*patterns, from_file: nil, format: :gitignore, root: nil) ⇒ Patterns
Returns a new instance of Patterns.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/path_list/patterns.rb', line 5 def initialize(*patterns, from_file: nil, format: :gitignore, root: nil) raise ArgumentError, "from_file: can't be used with patterns arguments" unless patterns.empty? || !from_file @format = format if from_file @root = root || ::File.dirname(from_file) @patterns = ::File.exist?(from_file) ? ::File.readlines(from_file) : [] else @root = root || ::Dir.pwd @patterns = patterns.flatten.flat_map { |string| string.to_s.lines } end @root += '/' unless @root.end_with?('/') end |