Class: Licensed::Dependency

Inherits:
License
  • Object
show all
Defined in:
lib/licensed/dependency.rb

Constant Summary collapse

/\A(AUTHORS|COPYING|NOTICE|LEGAL)(?:\..*)?\z/i

Constants inherited from License

License::YAML_FRONTMATTER_PATTERN

Instance Attribute Summary collapse

Attributes inherited from License

#text

Instance Method Summary collapse

Methods inherited from License

read, #save

Constructor Details

#initialize(path, metadata = {}) ⇒ Dependency

Returns a new instance of Dependency.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/licensed/dependency.rb', line 10

def initialize(path,  = {})
  @path = path
  @search_root = .delete("search_root")

  # with licensee now providing license_file[:dir],
  # enforcing absolute paths makes life much easier when determining
  # an absolute file path in notices\
  unless Pathname.new(path).absolute?
    raise "Dependency path #{path} must be absolute"
  end

  super 
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/licensed/dependency.rb', line 7

def path
  @path
end

#search_rootObject (readonly)

Returns the value of attribute search_root.



8
9
10
# File 'lib/licensed/dependency.rb', line 8

def search_root
  @search_root
end

Instance Method Details

#detect_license!Object



28
29
30
31
# File 'lib/licensed/dependency.rb', line 28

def detect_license!
  self["license"] = license_key
  self.text = ([license_text] + self.notices).compact.join("\n" + "-" * 80 + "\n")
end

#local_filesObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/licensed/dependency.rb', line 38

def local_files
  return [] unless Dir.exist?(path)

  Dir.foreach(path).map do |file|
    next unless file.match(LEGAL_FILES)

    file_path = File.join(path, file)
    next unless File.file?(file_path)

    file_path
  end.compact
end

#noticesObject

Extract legal notices from the dependency source



34
35
36
# File 'lib/licensed/dependency.rb', line 34

def notices
  local_files.uniq.map { |f| File.read(f) }
end

#projectObject



24
25
26
# File 'lib/licensed/dependency.rb', line 24

def project
  @project ||= Licensee::Projects::FSProject.new(path, search_root: search_root, detect_packages: true, detect_readme: true)
end