Class: Licensee::License
- Inherits:
-
Object
- Object
- Licensee::License
- Defined in:
- lib/licensee/license.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
-
#body ⇒ Object
(also: #to_s, #text)
The license body (e.g., contents - frontmatter).
-
#body_normalized ⇒ Object
License body with all whitespace replaced with a single space.
-
#content ⇒ Object
Raw content of license file, including YAML front matter.
- #featured? ⇒ Boolean (also: #featured)
-
#hashsig ⇒ Object
Git-computed hash signature for the license file.
-
#initialize(key) ⇒ License
constructor
A new instance of License.
- #inspect ⇒ Object
-
#meta ⇒ Object
License metadata from YAML front matter.
-
#name ⇒ Object
Returns the human-readable license name.
-
#path ⇒ Object
Path to vendored license file on disk.
- #url ⇒ Object
Constructor Details
#initialize(key) ⇒ License
Returns a new instance of License.
11 12 13 |
# File 'lib/licensee/license.rb', line 11 def initialize(key) @key=key.downcase end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/licensee/license.rb', line 9 def key @key end |
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'lib/licensee/license.rb', line 5 def self.all Licensee::licenses end |
Instance Method Details
#body ⇒ Object Also known as: to_s, text
The license body (e.g., contents - frontmatter)
53 54 55 |
# File 'lib/licensee/license.rb', line 53 def body @body ||= parts[2] if parts && parts[2] end |
#body_normalized ⇒ Object
License body with all whitespace replaced with a single space
60 61 62 |
# File 'lib/licensee/license.rb', line 60 def body_normalized @content_normalized ||= body.to_s.downcase.gsub(/\s+/, " ").strip end |
#content ⇒ Object
Raw content of license file, including YAML front matter
21 22 23 24 25 26 27 28 29 |
# File 'lib/licensee/license.rb', line 21 def content @content ||= if File.exists?(path) File.open(path).read elsif key == "other" # A pseudo-license with no content nil else raise Licensee::InvalidLicense, "'#{key}' is not a valid license key" end end |
#featured? ⇒ Boolean Also known as: featured
47 48 49 |
# File 'lib/licensee/license.rb', line 47 def featured? !!(["featured"] if ) end |
#hashsig ⇒ Object
Git-computed hash signature for the license file
65 66 67 68 69 70 |
# File 'lib/licensee/license.rb', line 65 def hashsig @hashsig ||= Rugged::Blob::HashSignature.new( body, Rugged::Blob::HashSignature::WHITESPACE_SMART) rescue Rugged::InvalidError nil end |
#inspect ⇒ Object
72 73 74 |
# File 'lib/licensee/license.rb', line 72 def inspect "#<Licensee::License key=\"#{key}\" name=\"#{name}\">" end |
#meta ⇒ Object
License metadata from YAML front matter
32 33 34 35 36 37 38 39 40 |
# File 'lib/licensee/license.rb', line 32 def ||= if parts && parts[1] if YAML.respond_to? :safe_load YAML.safe_load(parts[1]) else YAML.load(parts[1]) end end end |
#name ⇒ Object
Returns the human-readable license name
43 44 45 |
# File 'lib/licensee/license.rb', line 43 def name .nil? ? key.capitalize : ["title"] end |
#path ⇒ Object
Path to vendored license file on disk
16 17 18 |
# File 'lib/licensee/license.rb', line 16 def path @path ||= File. "#{@key}.txt", Licensee::Licenses.base end |
#url ⇒ Object
76 77 78 |
# File 'lib/licensee/license.rb', line 76 def url URI.join(Licensee::DOMAIN, ["permalink"]).to_s end |