class Licensed::Sources::Source
Attributes
all sources have a configuration
Public Class Methods
Source
# File lib/licensed/sources/source.rb, line 46 def self.full_type type_and_version.join("/") end
Returns the source name as a “/” delimited string of all the module and class names following “Licensed::Sources::”. This is the type that is used to distinguish multiple versions of a sources from each other. e.g. for ‘Licensed::Sources::Yarn::V1`, this returns `yarn/v1`
Source
# File lib/licensed/sources/source.rb, line 23 def self.inherited(klass) # register the inherited class as a source on the Licensed::Sources::Source class Licensed::Sources::Source.register_source(klass) end
Source
# File lib/licensed/sources/source.rb, line 71 def initialize(configuration) @config = configuration end
Source
# File lib/licensed/sources/source.rb, line 28 def self.register_source(klass) # add the source class to the known sources list return unless klass < Licensed::Sources::Source (@sources ||= []) << klass end
Source
# File lib/licensed/sources/source.rb, line 64 def self.require_matched_dependency_version false end
Returns true if the source requires matching reviewed and ignored dependencies’ versions as well as their name
Source
# File lib/licensed/sources/source.rb, line 38 def self.type type_and_version[0] end
Returns the source name as the first snake cased class or module name following “Licensed::Sources::”. This is the type that is included in metadata files and cache paths. e.g. for ‘Licensed::Sources::Yarn::V1`, this returns “yarn”
Source
# File lib/licensed/sources/source.rb, line 54 def self.type_and_version self.name.gsub("#{Licensed::Sources.name}::", "") .gsub(/([A-Z\d]+)([A-Z][a-z])/, "\\1_\\2".freeze) .gsub(/([a-z\d])([A-Z])/, "\\1_\\2".freeze) .downcase .split("::") end
Returns an array that includes the source’s type name at the first index, and optionally a version string for the source as the second index. Callers should override this function and not ‘type` or `full_type` when needing to adjust the default type and version parsing logic
Public Instance Methods
Source
# File lib/licensed/sources/source.rb, line 83 def dependencies cached_dependencies .reject { |d| ignored?(d) } .each { |d| add_additional_terms_from_configuration(d) } end
Returns all dependencies that should be evaluated. Excludes ignored dependencies.
Source
# File lib/licensed/sources/source.rb, line 77 def enabled? false end
Returns whether a source is enabled based on the environment in which licensed is run Defaults to false.
Source
# File lib/licensed/sources/source.rb, line 90 def enumerate_dependencies raise DependencyEnumerationNotImplementedError end
Enumerate all source dependencies. Must be implemented by each source class.
Source
# File lib/licensed/sources/source.rb, line 95 def ignored?(dependency) config.ignored?(dependency.metadata, require_version: self.class.require_matched_dependency_version) end
Returns whether a dependency is ignored in the configuration.
Source
# File lib/licensed/sources/source.rb, line 100 def source_config @source_config ||= config[self.class.type].is_a?(Hash) ? config[self.class.type] : {} end
Returns configuration options set for the current source
Private Instance Methods
Source
# File lib/licensed/sources/source.rb, line 112 def add_additional_terms_from_configuration(dependency) dependency.additional_terms.concat config.additional_terms_for_dependency("type" => self.class.type, "name" => dependency.name) end
Add any additional_terms for this dependency that have been added to the configuration
Source
# File lib/licensed/sources/source.rb, line 107 def cached_dependencies @dependencies ||= enumerate_dependencies.compact end
Returns a cached list of dependencies