class Cfoo::FileSystem
Public Class Methods
new(project_root, yaml_parser)
click to toggle source
# File lib/cfoo/file_system.rb, line 22 def initialize(project_root, yaml_parser) @project_root, @yaml_parser = project_root, yaml_parser end
Public Instance Methods
find_coordinates(string, file_name)
click to toggle source
# File lib/cfoo/file_system.rb, line 38 def find_coordinates(string, file_name) open(file_name) do |file| content = file.read lines = string.split "\n" patterns = lines.map { |line| Regexp.escape(line) } pattern = patterns.join '\n\s*' regex = %r[#{pattern}] index = regex =~ content if index.nil? raise CoordinatesNotFound, "Couldn't find '#{string.inspect}' in '#{file_name}'" else content.coordinates_of_index(index) end end end
glob_relative(path)
click to toggle source
# File lib/cfoo/file_system.rb, line 54 def glob_relative(path) absolute_files = Dir.glob(resolve_file path) absolute_files.map do |file| file.gsub(@project_root + '/', '') end end
list(path)
click to toggle source
# File lib/cfoo/file_system.rb, line 61 def list(path) Dir.glob("#{resolve_file path}/*") end
open(file_name, &block)
click to toggle source
# File lib/cfoo/file_system.rb, line 34 def open(file_name, &block) File.open(resolve_file(file_name), &block) end
parse_file(file_name)
click to toggle source
# File lib/cfoo/file_system.rb, line 30 def parse_file(file_name) @yaml_parser.load_file(resolve_file file_name) end
resolve_file(file_name)
click to toggle source
# File lib/cfoo/file_system.rb, line 26 def resolve_file(file_name) "#{@project_root}/#{file_name}" end