Class: R10K::Feature

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

Overview

Detect whether a given feature is present or absent

Defined Under Namespace

Classes: Collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}, &block) ⇒ Feature

Returns a new instance of Feature.

Parameters:

  • name (Symbol)

    The name of this feature

  • opts (Hash) (defaults to: {})
  • block (Proc)

    An optional block to detect if this feature is available

Options Hash (opts):

  • :libraries (String, Array<String>)

    One or more libraries to require to make sure this feature is present.



15
16
17
18
19
# File 'lib/r10k/feature.rb', line 15

def initialize(name, opts = {}, &block)
  @name      = name
  @libraries = Array(opts.delete(:libraries))
  @block     = block || lambda { true }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#available?true, false

Returns Is this feature available?.

Returns:

  • (true, false)

    Is this feature available?



22
23
24
# File 'lib/r10k/feature.rb', line 22

def available?
  @libraries.all? { |lib| library_available?(lib) } && !!@block.call
end