Class: Licensed::DependencyRecord
- Inherits:
-
Object
- Object
- Licensed::DependencyRecord
- Extended by:
- Forwardable
- Includes:
- Licensee::ContentHelper
- Defined in:
- lib/licensed/dependency_record.rb
Defined Under Namespace
Classes: License
Constant Summary collapse
- EXTENSION =
"dep.yml".freeze
Instance Attribute Summary collapse
-
#licenses ⇒ Object
readonly
Returns the value of attribute licenses.
-
#notices ⇒ Object
readonly
Returns the value of attribute notices.
Class Method Summary collapse
-
.read(filename) ⇒ Object
Read an existing record file.
Instance Method Summary collapse
-
#content ⇒ Object
Returns the content used to compare two licenses using normalization from ‘Licensee::CotentHelper`.
-
#initialize(licenses: [], notices: [], metadata: {}) ⇒ DependencyRecord
constructor
Construct a new record.
-
#matches?(other) ⇒ Boolean
Returns whether two records match based on their contents.
-
#save(filename) ⇒ Object
Save the metadata and text to a file.
Constructor Details
#initialize(licenses: [], notices: [], metadata: {}) ⇒ DependencyRecord
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
60 61 62 63 64 |
# File 'lib/licensed/dependency_record.rb', line 60 def initialize(licenses: [], notices: [], metadata: {}) @licenses = [licenses].flatten.compact.map { |l| DependencyRecord::License.new(l) } @notices = [notices].flatten.compact @metadata = end |
Instance Attribute Details
#licenses ⇒ Object (readonly)
Returns the value of attribute licenses.
52 53 54 |
# File 'lib/licensed/dependency_record.rb', line 52 def licenses @licenses end |
#notices ⇒ Object (readonly)
Returns the value of attribute notices.
53 54 55 |
# File 'lib/licensed/dependency_record.rb', line 53 def notices @notices end |
Class Method Details
.read(filename) ⇒ Object
Read an existing record file
filename - A String path to the file
Returns a Licensed::DependencyRecord
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/licensed/dependency_record.rb', line 40 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 ) end |
Instance Method Details
#content ⇒ Object
Returns the content used to compare two licenses using normalization from ‘Licensee::CotentHelper`
81 82 83 84 |
# File 'lib/licensed/dependency_record.rb', line 81 def content return if licenses.nil? || licenses.empty? licenses.map(&:text).compact.join end |
#matches?(other) ⇒ Boolean
Returns whether two records match based on their contents
87 88 89 90 |
# File 'lib/licensed/dependency_record.rb', line 87 def matches?(other) return false unless other.is_a?(DependencyRecord) self.content_normalized == other.content_normalized end |
#save(filename) ⇒ Object
Save the metadata and text to a file
filename - The destination file to save record contents at
69 70 71 72 73 74 75 76 77 |
# File 'lib/licensed/dependency_record.rb', line 69 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 |