Sha256: 3926528a46eee072361b313a82a01800133576b84e8b3c8c2c85a3b74d87ddc2

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

Dir[File.expand_path('*.rb', __dir__)].each { |file| require_relative file }

class FileStructure
    attr_reader :path, :use_glob

    def initialize(path, use_glob: true)
        @path = path
        @use_glob = use_glob
    end

    def self.expand(pattern, use_glob: true)
        if use_glob
            Dir.glob(pattern).select { |path| File.file?(path) }.map do |path|
                FileStructure.new(path, use_glob: use_glob)
            end
        else
            [FileStructure.new(pattern, use_glob: use_glob)]
        end
    end
end

class FileStructureValidator < ValidationStrategy
    def initialize(file)
        @file = file
    end

    def validate(project_path)
        full_path = File.join(project_path, @file.path)
        paths = @file.use_glob ? FileStructure.expand(full_path) : [@file]

        if paths.any? { |path| File.file?(path.path) }
            Solara.logger.passed("File exists: '#{@file.path}'")
        else
            raise ValidationError, "File missing: '#{@file.path}'"
        end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solara-0.2.0 solara/lib/core/doctor/validator/file_structure_validator.rb
solara-0.1.0 solara/lib/core/doctor/validator/file_structure_validator.rb