Class: Licensed::Sources::Source
- Inherits:
-
Object
- Object
- Licensed::Sources::Source
- Defined in:
- lib/licensed/sources/source.rb
Direct Known Subclasses
Bower, Bundler, Cabal, Cargo, Cocoapods, Composer, Dep, GitSubmodule, Go, Gradle, Manifest, Mix, NPM, NuGet, PNPM, Pip, Swift, Yarn::Berry, Yarn::V1
Defined Under Namespace
Classes: DependencyEnumerationNotImplementedError, Error
Class Attribute Summary collapse
-
.sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Attribute Summary collapse
-
#config ⇒ Object
all sources have a configuration.
Class Method Summary collapse
-
.full_type ⇒ Object
Returns the source name as a “/” delimited string of all the module and class names following “Licensed::Sources::”.
- .inherited(klass) ⇒ Object
- .register_source(klass) ⇒ Object
-
.require_matched_dependency_version ⇒ Object
Returns true if the source requires matching reviewed and ignored dependencies’ versions as well as their name.
-
.type ⇒ Object
Returns the source name as the first snake cased class or module name following “Licensed::Sources::”.
-
.type_and_version ⇒ Object
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.
Instance Method Summary collapse
-
#dependencies ⇒ Object
Returns all dependencies that should be evaluated.
-
#enabled? ⇒ Boolean
Returns whether a source is enabled based on the environment in which licensed is run Defaults to false.
-
#enumerate_dependencies ⇒ Object
Enumerate all source dependencies.
-
#ignored?(dependency) ⇒ Boolean
Returns whether a dependency is ignored in the configuration.
-
#initialize(configuration) ⇒ Source
constructor
A new instance of Source.
-
#source_config ⇒ Object
Returns configuration options set for the current source.
Constructor Details
#initialize(configuration) ⇒ Source
Returns a new instance of Source.
65 66 67 |
# File 'lib/licensed/sources/source.rb', line 65 def initialize(configuration) @config = configuration end |
Class Attribute Details
.sources ⇒ Object (readonly)
Returns the value of attribute sources.
15 16 17 |
# File 'lib/licensed/sources/source.rb', line 15 def sources @sources end |
Instance Attribute Details
#config ⇒ Object
all sources have a configuration
63 64 65 |
# File 'lib/licensed/sources/source.rb', line 63 def config @config end |
Class Method Details
.full_type ⇒ Object
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`
39 40 41 |
# File 'lib/licensed/sources/source.rb', line 39 def full_type type_and_version.join("/") end |
.inherited(klass) ⇒ Object
16 17 18 19 |
# File 'lib/licensed/sources/source.rb', line 16 def inherited(klass) # register the inherited class as a source on the Licensed::Sources::Source class Licensed::Sources::Source.register_source(klass) end |
.register_source(klass) ⇒ Object
21 22 23 24 25 |
# File 'lib/licensed/sources/source.rb', line 21 def register_source(klass) # add the source class to the known sources list return unless klass < Licensed::Sources::Source (@sources ||= []) << klass end |
.require_matched_dependency_version ⇒ Object
Returns true if the source requires matching reviewed and ignored dependencies’ versions as well as their name
57 58 59 |
# File 'lib/licensed/sources/source.rb', line 57 def require_matched_dependency_version false end |
.type ⇒ Object
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”
31 32 33 |
# File 'lib/licensed/sources/source.rb', line 31 def type type_and_version[0] end |
.type_and_version ⇒ Object
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
47 48 49 50 51 52 53 |
# File 'lib/licensed/sources/source.rb', line 47 def 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 |
Instance Method Details
#dependencies ⇒ Object
Returns all dependencies that should be evaluated. Excludes ignored dependencies.
77 78 79 80 81 |
# File 'lib/licensed/sources/source.rb', line 77 def dependencies cached_dependencies .reject { |d| ignored?(d) } .each { |d| add_additional_terms_from_configuration(d) } end |
#enabled? ⇒ Boolean
Returns whether a source is enabled based on the environment in which licensed is run Defaults to false.
71 72 73 |
# File 'lib/licensed/sources/source.rb', line 71 def enabled? false end |
#enumerate_dependencies ⇒ Object
Enumerate all source dependencies. Must be implemented by each source class.
84 85 86 |
# File 'lib/licensed/sources/source.rb', line 84 def enumerate_dependencies raise DependencyEnumerationNotImplementedError end |
#ignored?(dependency) ⇒ Boolean
Returns whether a dependency is ignored in the configuration.
89 90 91 |
# File 'lib/licensed/sources/source.rb', line 89 def ignored?(dependency) config.ignored?(dependency., require_version: self.class.require_matched_dependency_version) end |
#source_config ⇒ Object
Returns configuration options set for the current source
94 95 96 |
# File 'lib/licensed/sources/source.rb', line 94 def source_config @source_config ||= config[self.class.type].is_a?(Hash) ? config[self.class.type] : {} end |