Module: PuppetX::EnterpriseModules::Oracle::SourceFunctions

Defined in:
lib/puppet_x/enterprisemodules/oracle/source_functions.rb

Overview

This module provides functions to manage and compare Oracle source content.

It includes methods to check for errors, determine if the current content is in sync with the required content, and show differences between the two.

Examples:

Usage

if source_functions.insync?(current_state)
  # Do something if in sync
end

Instance Method Summary collapse

Instance Method Details

#contains_errors?Boolean

Checks if there are any compilation errors.

Returns:

  • (Boolean)

    True if there are compilation errors, false otherwise.



23
24
25
# File 'lib/puppet_x/enterprisemodules/oracle/source_functions.rb', line 23

def contains_errors?
  compilation_errors > 0
end

#insync?(_is) ⇒ Boolean

Compares the current content with the required content to determine if they are in sync.

Examples:

if insync?(current_state)
  # Content is in sync
end

Parameters:

  • _is (Object)

    The current state of the resource.

Returns:

  • (Boolean)

    True if the current content matches the required content, false otherwise.



36
37
38
39
40
41
42
43
44
# File 'lib/puppet_x/enterprisemodules/oracle/source_functions.rb', line 36

def insync?(_is)
  if current_content == required_content
    Puppet.warning "#{path}: #{resource.owner}.#{resource.java_name} up-to-date, but contains #{compilation_errors} error(s)." \
      if contains_errors? && resource.report_errors
    return true
  end
  show_diff(current_content, required_content)
  false
end

#show_diff(current_content, required_content) ⇒ Object

Shows the difference between current and required content.

Parameters:

  • current_content (String)

    The current content to compare.

  • required_content (String)

    The required content to compare.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/puppet_x/enterprisemodules/oracle/source_functions.rb', line 50

def show_diff(current_content, required_content)
  # Use a single Tempfile for both contents to reduce overhead
  Tempfile.create(['ora_java_source', nil]) do |current_content_file|
    current_content_file.write(current_content)
    current_content_file.flush

    Tempfile.create(['ora_java_source', nil]) do |required_content_file|
      required_content_file.write(required_content)
      required_content_file.flush

      file_diff = `diff #{current_content_file.path} #{required_content_file.path}`
      Puppet.info "#{path}: Difference is:\n#{file_diff}"
    end
  end
end