class Mudguard::Infrastructure::Persistence::RubyFiles
Provides access to all ruby-files of a project
Public Class Methods
select(project_path, patterns: nil)
click to toggle source
# File lib/mudguard/infrastructure/persistence/ruby_files.rb, line 12 def select(project_path, patterns: nil) project_exists = Dir.exist?(project_path) unless project_exists raise Mudguard::Domain::Error, "expected project #{project_path} doesn't exists" end patterns = [File.join("**", "*.rb")] if patterns.nil? enumerate_files(project_path, patterns) end
Private Class Methods
enumerate_files(project_path, patterns)
click to toggle source
# File lib/mudguard/infrastructure/persistence/ruby_files.rb, line 25 def enumerate_files(project_path, patterns) project_path_name = Pathname.new(project_path) ruby_files = patterns.map { |p| File.join(project_path, p) } Dir.glob(ruby_files).select { |f| File.file?(f) }.map do |f| file_path_name = Pathname.new(f) diff_path = file_path_name.relative_path_from(project_path_name).to_s Mudguard::Domain::Source.new(location: File.join("./", diff_path), code_loader: -> { File.read(f) }) end end