Class: PDK::Context::AbstractContext Abstract
- Inherits:
-
Object
- Object
- PDK::Context::AbstractContext
- Defined in:
- lib/pdk/context.rb
Overview
Abstract class which all PDK Contexts will subclass from.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context_path ⇒ String
readonly
The path used to create this context, for example the current working directory.
Instance Method Summary collapse
-
#display_name ⇒ Object
abstract
private
The friendly name to display for this context.
-
#initialize(context_path) ⇒ AbstractContext
constructor
A new instance of AbstractContext.
-
#parent_context ⇒ PDK::Context::AbstractContext, Nil
The context which this context is in.
-
#pdk_compatible? ⇒ Boolean
Whether the current context is compatible with the PDK e.g.
-
#root_path ⇒ String
The root of this context, for example the module root when inside a module.
-
#to_debug_log ⇒ Object
private
Writes the current context information, and parent contexts, to the PDK Debug Logger.
-
#to_s ⇒ Object
:nocov: There’s nothing to test here.
Constructor Details
#initialize(context_path) ⇒ AbstractContext
Returns a new instance of AbstractContext.
49 50 51 52 |
# File 'lib/pdk/context.rb', line 49 def initialize(context_path) @context_path = context_path @root_path = nil end |
Instance Attribute Details
#context_path ⇒ String (readonly)
The path used to create this context, for example the current working directory. This can be different from root_path For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as that is the root of the Module context
46 47 48 |
# File 'lib/pdk/context.rb', line 46 def context_path @context_path end |
Instance Method Details
#display_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The friendly name to display for this context
63 |
# File 'lib/pdk/context.rb', line 63 def display_name; end |
#parent_context ⇒ PDK::Context::AbstractContext, Nil
The context which this context is in. For example a Module Context (/controlrepo/site/profile) can be inside of a Control Repo context (/controlrepo) The default is to search in the parent directory of this context
68 69 70 71 |
# File 'lib/pdk/context.rb', line 68 def parent_context # Default detection is just look for the context in the parent directory of this context @parent_context || PDK::Context.create(File.dirname(root_path)) end |
#pdk_compatible? ⇒ Boolean
Whether the current context is compatible with the PDK e.g. in a Module context, whether it has the correct metadata.json content
56 57 58 |
# File 'lib/pdk/context.rb', line 56 def pdk_compatible? false end |
#root_path ⇒ String
The root of this context, for example the module root when inside a module. This can be different from context_path For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as that is the root of the Module context. Defaults to the context_path if not set.
38 39 40 |
# File 'lib/pdk/context.rb', line 38 def root_path @root_path || @context_path end |
#to_debug_log ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes the current context information, and parent contexts, to the PDK Debug Logger. This is mainly used by the PDK CLI when in debug mode to assist users to figure out why the PDK is misbehaving.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pdk/context.rb', line 76 def to_debug_log current = self depth = 1 loop do PDK.logger.debug("Detected #{current.display_name} at #{current.root_path.nil? ? current.context_path : current.root_path}") current = current.parent_context break if current.nil? depth += 1 # Circuit breaker in case there are circular references break if depth > 20 end nil end |
#to_s ⇒ Object
:nocov: There’s nothing to test here
92 93 94 |
# File 'lib/pdk/context.rb', line 92 def to_s "#<#{self.class}:#{object_id}>#{context_path}" end |