Class: CobraCommander::Umbrella
- Inherits:
-
Object
- Object
- CobraCommander::Umbrella
- Defined in:
- lib/cobra_commander/umbrella.rb
Overview
An umbrella application
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#components ⇒ Array<CobraCommander::Component>
All components in this umbrella.
-
#find(name) ⇒ ::CobraCommander::Component?
Finds a component by name.
-
#initialize(path, config = nil, **source_selector) ⇒ Umbrella
constructor
Umbrella constructor.
-
#load(**source_selector) ⇒ Object
Loads the given sources, or all of none given.
-
#resolve(path) ⇒ ::CobraCommander::Component?
Resolve a component given the path.
Constructor Details
#initialize(path, config = nil, **source_selector) ⇒ Umbrella
Umbrella constructor. This will load the given source packages.
22 23 24 25 26 27 |
# File 'lib/cobra_commander/umbrella.rb', line 22 def initialize(path, config = nil, **source_selector) @path = Pathname.new(path) @components = {} @config = config || Umbrella.load_config(@path.join("cobra.yml")) load(**source_selector) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/cobra_commander/umbrella.rb', line 8 def config @config end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/cobra_commander/umbrella.rb', line 8 def path @path end |
Class Method Details
.load_config(path) ⇒ Object
10 11 12 13 14 |
# File 'lib/cobra_commander/umbrella.rb', line 10 def self.load_config(path) return {} unless path.exist? YAML.safe_load(path.read, permitted_classes: [Symbol], aliases: true) end |
Instance Method Details
#components ⇒ Array<CobraCommander::Component>
All components in this umbrella
91 92 93 |
# File 'lib/cobra_commander/umbrella.rb', line 91 def components @components.values end |
#find(name) ⇒ ::CobraCommander::Component?
Finds a component by name
35 36 37 |
# File 'lib/cobra_commander/umbrella.rb', line 35 def find(name) @components[name] end |
#load(**source_selector) ⇒ Object
Loads the given sources, or all of none given. This method is fired by the constructor with the inital selector.
I.e.:
If the environment has both ruby and yarn plugins loaded, this
would load the yarn workspaces packages and rubygems package
graphs:
umbrella.load(ruby: true, js: true)
If no selector is given, all plugins are loaded. So assuming the
same plugins exist, this would also load yarn and ruby packages:
umbrella.load()
plugins will only load what is specified, and this would
only load ruby packages:
umbrella.load(ruby: true)
80 81 82 83 84 85 |
# File 'lib/cobra_commander/umbrella.rb', line 80 def load(**source_selector) Source.load(path, config["sources"], **source_selector).flatten.each do |package| @components[package.name] ||= Component.new(self, package.name) @components[package.name].add_package package end end |
#resolve(path) ⇒ ::CobraCommander::Component?
Resolve a component given the path.
This method resolves the component if the given path is inside any of the packages composing this component.
48 49 50 51 52 53 54 |
# File 'lib/cobra_commander/umbrella.rb', line 48 def resolve(path) components.find do |component| component.root_paths.any? do |component_path| component_path.eql?(path) || path..to_s.start_with?("#{component_path.expand_path}/") end end end |