class Nucleon::Core
Core
Nucleon
object¶ ↑
The Nucleon::Core
class defines a minimal base class for creating other capable objects, combining configurations, console capabilities, and logging capabilities.
All of the plugins build off of the Core
object, as do some utility classes.
Five main goals with this object:
-
Global and instance
Nucleon::Util::Logger
interfaces -
Global and instance
Nucleon::Util::Console
interfaces -
Include color methods
-
Provide contextually prefixed UI groups for console output operations
-
Provide an initialized lookup
Attributes
Nucleon::Util::Logger
-
Instance logger
Nucleon::Util::Console
-
Instance console
Public Class Methods
Return global logger instance
-
Parameters
-
Returns
Nucleon::Util::Logger
-
Global logger instance
-
Errors
# File lib/core/core.rb 135 def self.logger 136 return @@logger 137 end
Initialize a new core Nucleon
object
TODO: Figure out some way to make the console and logging systems pluggable?
-
Parameters
- nil,
Hash
,Nucleon::Config
-
data Configurations to import
- nil,
Hash
-
defaults Configuration defaults that may be overridden by config data
- Boolean
-
force Whether or not to force override of values where types don’t match during merge
- Boolean
-
set_initialized Whether or not to the initialized flag is set after this object is constructed
- Boolean
-
basic_merge Whether or not to perform a basic merge or deep (recursive) merge
-
Returns
- Void
-
This method does not return a value
-
Errors
See also:
Nucleon::Config::new
# File lib/core/core.rb 81 def initialize(data = {}, defaults = {}, force = true, set_initialized = true, basic_merge = true) 82 super(data, defaults, force, basic_merge) 83 84 @initialized = false 85 @class_color = Util::Data.ensure_value(delete(:class_color, :cyan), :cyan) 86 @class_label = self.class.to_s.downcase.gsub(/^nucleon::/, '') 87 88 self.logger = delete(:logger, @class_label) 89 self.ui = Config.new(export).defaults({ :resource => Util::Console.colorize(@class_label, @class_color) }) 90 91 logger.debug('Initialized instance logger and interface') 92 @initialized = true if set_initialized 93 end
Return global console instance
This is named ui for historical reasons. It might change to console in the future.
-
Parameters
-
Returns
Nucleon::Util::Console
-
Global console instance
-
Errors
# File lib/core/core.rb 175 def self.ui 176 return @@ui 177 end
Contextualize console operations in a code block with a given resource name.
TODO: May not need Mutex synchronization?
-
Parameters
- String, Symbol
-
resource Console resource identifier (prefix)
- Symbol
-
color Color to use; :black, :red, :green, :yellow, :blue, :purple, :cyan, :grey
-
Returns
- Void
-
This method does not return a value
-
Errors
-
Yields
Nucleon::Util::Console
-
ui Current global console instance
See also:
# File lib/core/core.rb 222 def self.ui_group(resource, color = :cyan) # :yields: ui 223 @@ui_lock.synchronize do 224 begin 225 ui_resource = ui.resource 226 ui.resource = Util::Console.colorize(resource, color) 227 yield(ui) 228 229 ensure 230 ui.resource = ui_resource 231 end 232 end 233 end
Public Instance Methods
Check if object is initialized?
The initialized flag must be set from a method within the class. It can not be set externally.
-
Parameters
-
Returns
- Boolean
-
Whether or not object has been marked as initialized
-
Errors
# File lib/core/core.rb 110 def initialized? 111 @initialized 112 end
Set current object logger instance
-
Parameters
- String,
Nucleon::Util::Logger
-
logger Logger instance or resource name for new logger
- String,
-
Returns
- Void
-
This method does not return a value
-
Errors
See also:
# File lib/core/core.rb 153 def logger=logger 154 Util::Logger.loggers.delete(self.logger.resource) if self.logger 155 156 if logger.is_a?(Util::Logger) 157 @logger = logger 158 else 159 @logger = Util::Logger.new(logger) 160 end 161 end
Set current object console instance
-
Parameters
- String,
Nucleon::Util::Console
-
ui Console instance or resource name for new console
- String,
-
Returns
- Void
-
This method does not return a value
-
Errors
See also:
# File lib/core/core.rb 192 def ui=ui 193 if ui.is_a?(Util::Console) 194 @ui = ui 195 else 196 @ui = Util::Console.new(ui) 197 end 198 end
Contextualize console operations in a code block with a given resource name.
-
Parameters
- String, Symbol
-
resource Console resource identifier (prefix)
- Symbol
-
color Color to use; :black, :red, :green, :yellow, :blue, :purple, :cyan, :grey
-
Returns
- Void
-
This method does not return a value
-
Errors
-
Yields
Nucleon::Util::Console
-
ui Current object console instance
See also:
# File lib/core/core.rb 252 def ui_group(resource, color = :cyan) # :yields: ui 253 ui_resource = ui.resource 254 ui.resource = Util::Console.colorize(resource, color) 255 yield(ui) 256 257 ensure 258 ui.resource = ui_resource 259 end