Module: R10K::Module

Defined in:
lib/r10k/module.rb

Defined Under Namespace

Classes: Base, Definition, Forge, Git, Local, MetadataFile, SVN, Tarball

Class Method Summary collapse

Class Method Details

.from_metadata(name, basedir, args, environment = nil) ⇒ Object

Takes the same signature as Module.new but returns an metadata module



31
32
33
34
35
36
37
38
39
# File 'lib/r10k/module.rb', line 31

def self.(name, basedir, args, environment=nil)
  with_implementation(name, args) do |implementation|
    R10K::Module::Definition.new(name,
                                 dirname: basedir,
                                 args: args,
                                 implementation: implementation,
                                 environment: environment)
  end
end

.new(name, basedir, args, environment = nil) ⇒ Object < R10K::Module] A member of the implementing subclass

Look up the implementing class and instantiate an object

This method takes the arguments for normal object generation and checks all inheriting classes to see if they implement the behavior needed to create the requested object. It selects the first class that can implement an object with ‘name, args`, and generates an object of that class.

Parameters:

  • name (String)

    The unique name of the module

  • basedir (String)

    The root to install the module in

  • args (Hash)

    An arbitary Hash that specifies the implementation

  • environment (R10K::Environment) (defaults to: nil)

    Optional environment that this module is a part of

Returns:

  • (Object < R10K::Module] A member of the implementing subclass)

    Object < R10K::Module] A member of the implementing subclass



24
25
26
27
28
# File 'lib/r10k/module.rb', line 24

def self.new(name, basedir, args, environment=nil)
  with_implementation(name, args) do |implementation|
    implementation.new(name, basedir, args, environment)
  end
end

.register(klass) ⇒ Object

Register an module implementation for later generation



6
7
8
9
# File 'lib/r10k/module.rb', line 6

def self.register(klass)
  @klasses ||= []
  @klasses << klass
end

.with_implementation(name, args, &block) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/r10k/module.rb', line 41

def self.with_implementation(name, args, &block)
  if implementation = @klasses.find { |klass| klass.implement?(name, args) }
    block.call(implementation)
  else
    raise _("Module %{name} with args %{args} doesn't have an implementation. (Are you using the right arguments?)") % {name: name, args: args.inspect}
  end
end