Class: OctocatalogDiff::CatalogUtil::ENC

Inherits:
Object
  • Object
show all
Defined in:
lib/octocatalog-diff/catalog-util/enc.rb,
lib/octocatalog-diff/catalog-util/enc/pe.rb,
lib/octocatalog-diff/catalog-util/enc/noop.rb,
lib/octocatalog-diff/catalog-util/enc/pe/v1.rb,
lib/octocatalog-diff/catalog-util/enc/script.rb

Overview

Support a generic ENC. It must use one of the supported backends found in the ‘enc’ subdirectory.

Defined Under Namespace

Classes: Noop, PE, Script

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ENC

Constructor

Parameters:

  • :backend (Symbol)

    If set, this will force a backend

  • :enc (String)

    Path to ENC script (node_terminus = exec)

  • #

    FIXME: Add support for PE’s ENC endpoint API



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/octocatalog-diff/catalog-util/enc.rb', line 21

def initialize(options = {})
  @options = options

  # Determine appropriate backend based on options supplied
  @enc_obj = backend

  # Initialize instance variables for content and error message.
  @builder = @enc_obj.class.to_s

  # Set the executed flag to false, so that it can be executed when something is retrieved.
  @executed = false
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



15
16
17
# File 'lib/octocatalog-diff/catalog-util/enc.rb', line 15

def builder
  @builder
end

Instance Method Details

#content(logger = nil) ⇒ String

Retrieve content

Returns:

  • (String)

    ENC content, or nil if there was an error



36
37
38
39
# File 'lib/octocatalog-diff/catalog-util/enc.rb', line 36

def content(logger = nil)
  execute(logger)
  @content ||= @enc_obj.content
end

#error_message(logger = nil) ⇒ String

Retrieve error message

Returns:

  • (String)

    Error message, or nil if there was no error



43
44
45
46
# File 'lib/octocatalog-diff/catalog-util/enc.rb', line 43

def error_message(logger = nil)
  execute(logger)
  @error_message ||= @enc_obj.error_message
end

#execute(logger = nil) ⇒ Object

Execute the ‘execute’ method of the object, but only once

Parameters:

  • Logger (Logger)

    (optional) - if not supplied any logger messages will be discarded



50
51
52
53
54
55
56
57
# File 'lib/octocatalog-diff/catalog-util/enc.rb', line 50

def execute(logger = nil)
  return if @executed
  logger ||= @options[:logger]
  logger ||= Logger.new(StringIO.new)
  @enc_obj.execute(logger) if @enc_obj.respond_to?(:execute)
  @executed = true
  override_enc_parameters(logger)
end