Sha256: c5532300147f5c34e69e111cca8dc2e69b00d1431b47dbd27fe9122c655a500e

Contents?: true

Size: 1002 Bytes

Versions: 9

Compression:

Stored size: 1002 Bytes

Contents

# Filesystem-based project
#
# Analyze a folder on the filesystem for license information
module Licensee
  class FSProject < Project
    def initialize(path, **args)
      if ::File.file?(path)
        @pattern = ::File.basename(path)
        @dir = ::File.dirname(path)
      else
        @pattern = '*'
        @dir = path
      end
      super(**args)
    end

    private

    # Returns an array of hashes representing the project's files.
    # Hashes will have the :name key, with the relative path to the file
    def files
      files = []

      Dir.glob(::File.join(@dir, @pattern).tr('\\', '/')) do |file|
        next unless ::File.file?(file)
        files.push(name: ::File.basename(file))
      end

      files
    end

    # Retrieve a file's content from disk
    #
    # file - the file hash, with the :name key as the file's relative path
    #
    # Returns the file contents as a string
    def load_file(file)
      ::File.read(::File.join(@dir, file[:name]))
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
licensee-8.9.2 lib/licensee/projects/fs_project.rb
licensee-8.9.0 lib/licensee/projects/fs_project.rb
licensee-8.8.5 lib/licensee/projects/fs_project.rb
licensee-8.8.4 lib/licensee/projects/fs_project.rb
licensee-8.8.3 lib/licensee/projects/fs_project.rb
licensee-8.8.2 lib/licensee/projects/fs_project.rb
licensee-8.8.1 lib/licensee/projects/fs_project.rb
licensee-8.8.0 lib/licensee/projects/fs_project.rb
licensee-8.7.0 lib/licensee/projects/fs_project.rb