Class: RuneRb::Core::Unit Abstract
- Inherits:
-
Object
- Object
- RuneRb::Core::Unit
- Extended by:
- Dry::Configurable
- Includes:
- Dry::Container::Mixin, Logging, Singleton
- Defined in:
- lib/rune/core/unit.rb
Overview
This class is abstract.
A Unit is a Dry::Container that encapsulates specific logic for a given system. Units are used to construct and run certain parts of the game. All Unit instances should include the Singletons.
Instance Method Summary collapse
-
#initialize ⇒ Unit
constructor
Constructs a new instance of Unit and sets the name to the class name.
-
#prepare ⇒ Object
Prepares the unit for use.
Methods included from Logging
Constructor Details
#initialize ⇒ Unit
Constructs a new instance of RuneRb::Core::Unit and sets the name to the class name.
11 12 13 14 |
# File 'lib/rune/core/unit.rb', line 11 def initialize @name = self.class.name.split('::')[-2] super end |
Instance Method Details
#prepare ⇒ Object
Prepares the unit for use. Providers are loaded and imported based on the configuration.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rune/core/unit.rb', line 17 def prepare info "Preparing #{@name} unit." # Determine directory based on the class of the current instance class_directory = File.dirname(self.class.instance_method(:prepare).source_location.first) providers_directory = File.join(class_directory, 'providers', '*.rb') # Load providers Dir[providers_directory].sort.each { |provider| require provider } end |