Class: R10K::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/r10k/module.rb

Direct Known Subclasses

Forge, Git

Defined Under Namespace

Classes: Forge, Git

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, args) ⇒ Module

Returns a new instance of Module.



35
36
37
# File 'lib/r10k/module.rb', line 35

def initialize(name, path, args)
  @name, @path, @args = name, path, args
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



33
34
35
# File 'lib/r10k/module.rb', line 33

def name
  @name
end

#pathObject

Returns the value of attribute path.



33
34
35
# File 'lib/r10k/module.rb', line 33

def path
  @path
end

Class Method Details

.inherited(klass) ⇒ Object

Register an inheriting class for later generation



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

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

.new(name, path, args) ⇒ 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

  • path (String)

    The root path to install the module in

  • args (Object)

    An arbitary value or set of values that specifies the implementation

Returns:

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

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



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

def self.new(name, path, args)
  if implementation = @klasses.find { |klass| klass.implements(name, args) }
    obj = implementation.send(:allocate)
    obj.send(:initialize, name, path, args)
    obj
  else
    raise "Module #{name} with args #{args.inspect} doesn't have an implementation. (Are you using the right arguments?)"
  end
end

Instance Method Details

#full_pathObject



39
40
41
# File 'lib/r10k/module.rb', line 39

def full_path
  File.join(@path, @name)
end