Class: Licensee::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/licensee/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_or_repo, revision = nil) ⇒ Project

Initializes a new project

path_or_repo path to git repo or Rugged::Repository instance revsion - revision ref, if any



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/licensee/project.rb', line 9

def initialize(path_or_repo, revision = nil)
  if path_or_repo.kind_of? Rugged::Repository
    @repository = path_or_repo
  else
    begin
      @repository = Rugged::Repository.new(path_or_repo)
    rescue Rugged::RepositoryError
      if revision
        raise
      else
        @repository = FilesystemRepository.new(path_or_repo)
      end
    end
  end

  @revision = revision
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



3
4
5
# File 'lib/licensee/project.rb', line 3

def repository
  @repository
end

Class Method Details

.match_license_file(filename) ⇒ Object

Scores a given file as a potential license

filename - (string) the name of the file to score

Returns 1.0 if the file is definately a license file Returns 0.75 if the file is probably a license file Returns 0.5 if the file is likely a license file Returns 0.0 if the file is definately not a license file



45
46
47
48
49
50
# File 'lib/licensee/project.rb', line 45

def self.match_license_file(filename)
  return 1.0  if filename =~ /\A(un)?licen[sc]e(\.[^.]+)?\z/i
  return 0.75 if filename =~ /\Acopy(ing|right)(\.[^.]+)?\z/i
  return 0.5  if filename =~ /licen[sc]e/i
  return 0.0
end

Instance Method Details

#licenseObject

Returns the matching Licensee::License instance if a license can be detected



33
34
35
# File 'lib/licensee/project.rb', line 33

def license
  @license ||= license_file.match if license_file
end

#license_fileObject

Returns an instance of Licensee::LicenseFile if there’s a license file detected



28
29
30
# File 'lib/licensee/project.rb', line 28

def license_file
  @license_file ||= LicenseFile.new(license_blob, :path => license_path) if license_blob
end