Sha256: f6761bcc9da778d86d06014d4bea57963181e3bb7617cd2fc53f108684d6fc05

Contents?: true

Size: 1.54 KB

Versions: 29

Compression:

Stored size: 1.54 KB

Contents

module UniverseCompiler
  module Universe

    module Compile

      include UniverseCompiler::Utils::DeepTraverse

      def compile(scenario: nil)
        valid? raise_error: true
        UniverseCompiler.logger.info "Starting compilation of universe '#{name}'"
        # Pass 1 - Universe duplication
        target_universe = dup

        # Pass 2 - Applying entities inheritance
        target_universe.apply_entities_inheritance

        # Apply scenario
        target_universe.apply_entities_overrides scenario unless scenario.nil?

        UniverseCompiler.logger.info "Completed compilation of universe '#{name}' into '#{target_universe.name}'"
        target_universe
      end

      protected

      def apply_entities_overrides(scenario)
        UniverseCompiler.logger.debug "Starting override process for universe '#{name}'."
        candidates = by_type.fetch(UniverseCompiler::Entity::Override.entity_type, []).select { |overrider| overrider.scenario == scenario }
        UniverseCompiler.logger.warn "No override found for scenario '#{scenario}' in universe '#{name}'." if candidates.empty?
        candidates.each(&:apply_overrides)
        UniverseCompiler.logger.debug "Completed override process for universe '#{name}'."
        self
      end

      def apply_entities_inheritance
        UniverseCompiler.logger.debug "Starting inheritance process for universe '#{name}'."
        entities.each(&:apply_inheritance)
        UniverseCompiler.logger.debug "Completed inheritance process for universe '#{name}'."
        self
      end

    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
universe_compiler-0.5.6 lib/universe_compiler/universe/compile.rb
universe_compiler-0.5.5 lib/universe_compiler/universe/compile.rb
universe_compiler-0.5.4 lib/universe_compiler/universe/compile.rb
universe_compiler-0.5.3 lib/universe_compiler/universe/compile.rb
universe_compiler-0.5.2 lib/universe_compiler/universe/compile.rb
universe_compiler-0.5.1 lib/universe_compiler/universe/compile.rb
universe_compiler-0.4.3 lib/universe_compiler/universe/compile.rb
universe_compiler-0.4.2 lib/universe_compiler/universe/compile.rb
universe_compiler-0.4.1 lib/universe_compiler/universe/compile.rb
universe_compiler-0.4.0 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.12 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.11 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.10 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.9 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.8 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.7 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.6 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.5 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.4 lib/universe_compiler/universe/compile.rb
universe_compiler-0.3.3 lib/universe_compiler/universe/compile.rb