Module: Licensee::License::ClassMethods
- Included in:
- Licensee::License
- Defined in:
- lib/licensee/license/class_methods.rb
Overview
Class-level lookup and caching for licenses.
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
All license objects defined via Licensee (via choosealicense.com).
- #find(key, options = {}) ⇒ Object (also: #[], #find_by_key)
-
#find_by_title(title) ⇒ Object
Given a license title or nickname, fuzzy match the license.
- #keys ⇒ Object
- #license_dir ⇒ Object
- #license_files ⇒ Object
- #spdx_dir ⇒ Object
Instance Method Details
#all(options = {}) ⇒ Object
All license objects defined via Licensee (via choosealicense.com)
Options:
-
:hidden - boolean, return hidden licenses (default: false)
-
:featured - boolean, return only (non)featured licenses (default: all)
Returns an Array of License objects.
14 15 16 17 18 19 20 21 22 |
# File 'lib/licensee/license/class_methods.rb', line 14 def all( = {}) @all[] ||= begin = LicenseAllHelper.(, DEFAULT_OPTIONS) output = licenses.dup LicenseAllHelper.apply_all_filters!(output, ) output.sort_by!(&:key) LicenseAllHelper.filter_featured(output, [:featured]) end end |
#find(key, options = {}) ⇒ Object Also known as: [], find_by_key
30 31 32 33 |
# File 'lib/licensee/license/class_methods.rb', line 30 def find(key, = {}) = { hidden: true }.merge() keys_licenses()[key.downcase] end |
#find_by_title(title) ⇒ Object
Given a license title or nickname, fuzzy match the license
38 39 40 41 42 |
# File 'lib/licensee/license/class_methods.rb', line 38 def find_by_title(title) License.all(hidden: true, pseudo: false).find do |license| title =~ /\A(the )?#{license.title_regex}( license)?\z/i end end |
#keys ⇒ Object
24 25 26 27 28 |
# File 'lib/licensee/license/class_methods.rb', line 24 def keys @keys ||= license_files.map do |license_file| ::File.basename(license_file, '.txt').downcase end + PSEUDO_LICENSES end |
#license_dir ⇒ Object
44 45 46 |
# File 'lib/licensee/license/class_methods.rb', line 44 def license_dir ::File. '../../../vendor/choosealicense.com/_licenses', __dir__ end |
#license_files ⇒ Object
48 49 50 |
# File 'lib/licensee/license/class_methods.rb', line 48 def license_files @license_files ||= Dir.glob("#{license_dir}/*.txt") end |
#spdx_dir ⇒ Object
52 53 54 |
# File 'lib/licensee/license/class_methods.rb', line 52 def spdx_dir ::File. '../../../vendor/license-list-XML/src', __dir__ end |