Class: RuneRb::Core::Unit Abstract

Inherits:
Object
  • Object
show all
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.

Since:

  • 0.1.0

Instance Method Summary collapse

Methods included from Logging

#err, #err!, #log, #log!

Constructor Details

#initializeUnit

Constructs a new instance of RuneRb::Core::Unit and sets the name to the class name.

Since:

  • 0.1.0



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

#prepareObject

Prepares the unit for use. Providers are loaded and imported based on the configuration.

Since:

  • 0.1.0



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