Class: Licensed::AppConfiguration
- Inherits:
-
Hash
- Object
- Hash
- Licensed::AppConfiguration
- Defined in:
- lib/licensed/configuration.rb
Constant Summary collapse
- DIRECTORY_NAME_GENERATOR_KEY =
"directory_name".freeze
- RELATIVE_PATH_GENERATOR_KEY =
"relative_path".freeze
- DEFAULT_RELATIVE_PATH_NAME_SEPARATOR =
"-".freeze
- ALL_NAME_GENERATOR_KEYS =
[DIRECTORY_NAME_GENERATOR_KEY, RELATIVE_PATH_GENERATOR_KEY].freeze
- DEFAULT_CACHE_PATH =
".licenses".freeze
Class Method Summary collapse
-
.root_for(configuration) ⇒ Object
Returns the root for a configuration in following order of precedence: 1.
Instance Method Summary collapse
-
#additional_terms_for_dependency(dependency) ⇒ Object
Returns an array of paths to files containing additional license terms.
-
#allow(license) ⇒ Object
Set a license as explicitly allowed.
-
#allowed?(license) ⇒ Boolean
Is the license of the dependency allowed?.
-
#cache_path ⇒ Object
Returns the path to the app cache directory as a Pathname.
-
#enabled?(source_type) ⇒ Boolean
Returns whether a source type is enabled.
-
#ignore(dependency) ⇒ Object
Ignore a dependency.
-
#ignored?(dependency) ⇒ Boolean
Is the given dependency ignored?.
-
#initialize(options = {}, inherited_options = {}) ⇒ AppConfiguration
constructor
A new instance of AppConfiguration.
- #pwd ⇒ Object
-
#review(dependency, at_version: false) ⇒ Object
Set a dependency as reviewed.
-
#reviewed?(dependency, match_version: false) ⇒ Boolean
Is the given dependency reviewed?.
-
#reviewed_versions(dependency) ⇒ Object
Find all reviewed dependencies that match the provided dependency’s name.
-
#root ⇒ Object
Returns the path to the workspace root as a Pathname.
-
#source_path ⇒ Object
Returns the path to the app source directory as a Pathname.
-
#sources ⇒ Object
Returns an array of enabled app sources.
Constructor Details
#initialize(options = {}, inherited_options = {}) ⇒ AppConfiguration
Returns a new instance of AppConfiguration.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/licensed/configuration.rb', line 21 def initialize( = {}, = {}) super() # update order: # 1. anything inherited from root config # 2. explicitly configured app settings update() update() verify_arg "source_path" self["sources"] ||= {} self["reviewed"] ||= {} self["ignored"] ||= {} self["allowed"] ||= [] self["root"] = AppConfiguration.root_for(self) self["name"] = generate_app_name # setting the cache path might need a valid app name. # this must come after setting self["name"] self["cache_path"] = detect_cache_path(, ) end |
Class Method Details
.root_for(configuration) ⇒ Object
Returns the root for a configuration in following order of precedence:
-
explicitly configured “root” property
-
a found git repository root
-
the current directory
17 18 19 |
# File 'lib/licensed/configuration.rb', line 17 def self.root_for(configuration) configuration["root"] || Licensed::Git.repository_root || Dir.pwd end |
Instance Method Details
#additional_terms_for_dependency(dependency) ⇒ Object
Returns an array of paths to files containing additional license terms.
113 114 115 116 |
# File 'lib/licensed/configuration.rb', line 113 def additional_terms_for_dependency(dependency) amendment_paths = Array(self.dig("additional_terms", dependency["type"], dependency["name"])) amendment_paths.flat_map { |path| Dir.glob(self.root.join(path)) } end |
#allow(license) ⇒ Object
Set a license as explicitly allowed
108 109 110 |
# File 'lib/licensed/configuration.rb', line 108 def allow(license) self["allowed"] << license end |
#allowed?(license) ⇒ Boolean
Is the license of the dependency allowed?
91 92 93 |
# File 'lib/licensed/configuration.rb', line 91 def allowed?(license) Array(self["allowed"]).include?(license) end |
#cache_path ⇒ Object
Returns the path to the app cache directory as a Pathname
48 49 50 |
# File 'lib/licensed/configuration.rb', line 48 def cache_path root.join(self["cache_path"]) end |
#enabled?(source_type) ⇒ Boolean
Returns whether a source type is enabled
69 70 71 72 73 |
# File 'lib/licensed/configuration.rb', line 69 def enabled?(source_type) # the default is false if any sources are set to true, true otherwise default = !self["sources"].any? { |_, enabled| enabled } self["sources"].fetch(source_type, default) end |
#ignore(dependency) ⇒ Object
Ignore a dependency
96 97 98 |
# File 'lib/licensed/configuration.rb', line 96 def ignore(dependency) (self["ignored"][dependency["type"]] ||= []) << dependency["name"] end |
#ignored?(dependency) ⇒ Boolean
Is the given dependency ignored?
86 87 88 |
# File 'lib/licensed/configuration.rb', line 86 def ignored?(dependency) any_list_pattern_matched? self["ignored"][dependency["type"]], dependency end |
#pwd ⇒ Object
57 58 59 |
# File 'lib/licensed/configuration.rb', line 57 def pwd Pathname.pwd end |
#review(dependency, at_version: false) ⇒ Object
Set a dependency as reviewed
101 102 103 104 105 |
# File 'lib/licensed/configuration.rb', line 101 def review(dependency, at_version: false) id = dependency["name"] id += "@#{dependency["version"]}" if at_version && dependency["version"] (self["reviewed"][dependency["type"]] ||= []) << id end |
#reviewed?(dependency, match_version: false) ⇒ Boolean
Is the given dependency reviewed?
76 77 78 |
# File 'lib/licensed/configuration.rb', line 76 def reviewed?(dependency, match_version: false) any_list_pattern_matched? self["reviewed"][dependency["type"]], dependency, match_version: match_version end |
#reviewed_versions(dependency) ⇒ Object
Find all reviewed dependencies that match the provided dependency’s name
81 82 83 |
# File 'lib/licensed/configuration.rb', line 81 def reviewed_versions(dependency) similar_list_patterns self["reviewed"][dependency["type"]], dependency end |
#root ⇒ Object
Returns the path to the workspace root as a Pathname.
43 44 45 |
# File 'lib/licensed/configuration.rb', line 43 def root @root ||= Pathname.new(self["root"]) end |
#source_path ⇒ Object
Returns the path to the app source directory as a Pathname
53 54 55 |
# File 'lib/licensed/configuration.rb', line 53 def source_path root.join(self["source_path"]) end |