Sha256: 82fcf19e43c8f6ad477aa43816936afc45e1626628ffd29e51a84fdf36835cfe

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

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

class DirectoryStructure
    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.directory?(path) }.map do |path|
                DirectoryStructure.new(path, use_glob: use_glob)
            end
        else
            [DirectoryStructure.new(pattern, use_glob: use_glob)]
        end
    end
end

class DirectoryStructureValidator < ValidationStrategy
    def initialize(dir)
        @dir = dir
    end

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

        if paths.any? { |path| File.directory?(path.path) }
            Solara.logger.passed("Directory exists: '#{@dir.path}'")
        else
            raise ValidationError, "Directory missing: '#{@dir.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/directory_structure_validator.rb
solara-0.1.0 solara/lib/core/doctor/validator/directory_structure_validator.rb