class Licensed::DependencyRecord
Constants
- EXTENSION
Attributes
Public Class Methods
Source
# File lib/licensed/dependency_record.rb, line 72 def initialize(licenses: [], notices: [], metadata: {}) @licenses = [licenses].flatten.compact.map { |l| DependencyRecord::License.new(l) } @notices = [notices].flatten.compact @metadata = metadata end
Construct a new record
licenses - a string, or array of strings, representing the content of each license notices - a string, or array of strings, representing the content of each legal notice metadata - a Hash of the metadata for the package
Source
# File lib/licensed/dependency_record.rb, line 50 def self.read(filename) return unless File.exist?(filename) data = YAML.load_file(filename) return if data.nil? || data.empty? new( licenses: data.delete("licenses"), notices: data.delete("notices"), metadata: data ) rescue Psych::SyntaxError => e raise Licensed::DependencyRecord::Error.new(e.message) end
Read an existing record file
filename - A String path to the file
Returns a Licensed::DependencyRecord
Public Instance Methods
Source
# File lib/licensed/dependency_record.rb, line 93 def content return if licenses.nil? || licenses.empty? licenses.sort_by(&:key).map(&:text).compact.join end
Returns the content used to compare two licenses using normalization from ‘Licensee::CotentHelper`
Source
# File lib/licensed/dependency_record.rb, line 99 def matches?(other) return false unless other.is_a?(DependencyRecord) self.content_normalized == other.content_normalized end
Returns whether two records match based on their contents
Source
# File lib/licensed/dependency_record.rb, line 81 def save(filename) data_to_save = @metadata.merge({ "licenses" => licenses.map(&:to_cache), "notices" => notices }) FileUtils.mkdir_p(File.dirname(filename)) File.write(filename, data_to_save.to_yaml) end
Save the metadata and text to a file
filename - The destination file to save record contents at