Class: CobraCommander::Umbrella

Inherits:
Object
  • Object
show all
Defined in:
lib/cobra_commander/umbrella.rb

Overview

An umbrella application

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, config = nil, **source_selector) ⇒ Umbrella

Umbrella constructor. This will load the given source packages.

Parameters:

  • path (String, Pathname)

    path to umbrella app

  • **source_selector (Symbol => Boolean)

    selector as explained above

See Also:



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

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/cobra_commander/umbrella.rb', line 8

def config
  @config
end

#pathObject (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

#componentsArray<CobraCommander::Component>

All components in this umbrella

Returns:



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

Parameters:

  • name (String)

    the name of the component

Returns:



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()

Specifying plugins will only load what is specified, and this would
only load ruby packages:

   umbrella.load(ruby: true)

See Also:



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.

Parameters:

  • path (String, Pathname)

    the path to be resolved

Returns:



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.expand_path.to_s.start_with?("#{component_path.expand_path}/")
    end
  end
end