Sha256: 9401b0819554939b9ea227168505a8e745047d6a92c1ce67e762410f47e02661
Contents?: true
Size: 1.5 KB
Versions: 4
Compression:
Stored size: 1.5 KB
Contents
class Licensee class License def self.all Licensee::licenses end attr_reader :key def initialize(key) @key=key.downcase end # Path to vendored license file on disk def path @path ||= File.expand_path "#{@key}.txt", Licensee::Licenses.base end # Raw content of license file, including YAML front matter def content @content ||= File.open(path).read rescue "" end # License metadata from YAML front matter def meta @meta ||= YAML.load(parts[1]) if parts[1] rescue nil end def name meta["title"] if meta end def featured? meta["featured"] if meta end alias_method :featured, :featured? # The license body (e.g., contents - frontmatter) def body @body ||= parts[2] if parts[2] end alias_method :to_s, :body alias_method :text, :body # License body with all whitespace replaced with a single space def body_normalized @content_normalized ||= body.to_s.downcase.gsub(/\s+/, " ").strip end # Git-computed hash signature for the license file def hashsig @hashsig ||= Rugged::Blob::HashSignature.new( body, Rugged::Blob::HashSignature::WHITESPACE_SMART) end def inspect "#<Licensee::License key=\"#{key}\" name=\"#{name}\">" end def url URI.join(Licensee::DOMAIN, meta["permalink"]).to_s end private def parts @parts ||= content.match(/^(---\n.*\n---)?(.*)/m).to_a end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
licensee-4.2.3 | lib/licensee/license.rb |
licensee-4.2.2 | lib/licensee/license.rb |
licensee-4.2.1 | lib/licensee/license.rb |
licensee-4.2.0 | lib/licensee/license.rb |