Class: R10K::Feature

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

Overview

Detect whether a given feature is present or absent

Defined Under Namespace

Classes: Collection

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

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.



19
20
21
22
23
# File 'lib/r10k/feature.rb', line 19

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/r10k/feature.rb', line 11

def name
  @name
end

Instance Method Details

#available?true, false

Returns Is this feature available?.

Returns:

  • (true, false)

    Is this feature available?



26
27
28
29
30
31
32
# File 'lib/r10k/feature.rb', line 26

def available?
  logger.debug1 { _("Testing to see if feature %{name} is available.") % {name: @name} }
  rv = @libraries.all? { |lib| library_available?(lib) } && proc_available?
  msg = rv ? "is" : "is not"
  logger.debug1 { _("Feature %{name} %{message} available.") % {name: @name, message: msg} }
  rv
end