Class: Licensed::License
- Inherits:
-
Object
- Object
- Licensed::License
- Extended by:
- Forwardable
- Defined in:
- lib/licensed/license.rb
Direct Known Subclasses
Constant Summary collapse
- YAML_FRONTMATTER_PATTERN =
/\A---\s*\n(.*?\n?)^---\s*$\n?(.*)\z/m
- LEGAL_FILES =
/\A(COPYING|NOTICE|LEGAL)(?:\..*)?\z/i
Instance Attribute Summary collapse
-
#text ⇒ Object
The license text and other legal notices.
Class Method Summary collapse
-
.read(filename) ⇒ Object
Read an existing license file.
Instance Method Summary collapse
-
#initialize(metadata = {}, text = nil) ⇒ License
constructor
Construct a new license.
-
#save(filename) ⇒ Object
Save the metadata and license to a file.
Constructor Details
#initialize(metadata = {}, text = nil) ⇒ License
Construct a new license
filename - the String path of the file metadata - a Hash of the metadata for the package text - a String of the license text and other legal notices
31 32 33 34 |
# File 'lib/licensed/license.rb', line 31 def initialize( = {}, text = nil) @metadata = @text = text end |
Instance Attribute Details
#text ⇒ Object
The license text and other legal notices
24 25 26 |
# File 'lib/licensed/license.rb', line 24 def text @text end |
Class Method Details
.read(filename) ⇒ Object
Read an existing license file
filename - A String path to the file
Returns a Licensed::License
15 16 17 18 |
# File 'lib/licensed/license.rb', line 15 def self.read(filename) match = File.read(filename).scrub.match(YAML_FRONTMATTER_PATTERN) new(YAML.load(match[1]), match[2]) end |
Instance Method Details
#save(filename) ⇒ Object
Save the metadata and license to a file
37 38 39 40 |
# File 'lib/licensed/license.rb', line 37 def save(filename) FileUtils.mkdir_p(File.dirname(filename)) File.write(filename, YAML.dump(@metadata) + "---\n#{text}") end |