Sha256: a532478840bf5210c21f301a17306efebad7c586caa428c58c5066e059be57d5

Contents?: true

Size: 1.66 KB

Versions: 42

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require 'avm/instances/configuration'
require 'eac_launcher/paths/real'
require 'eac_ruby_utils/core_ext'
require 'avm/projects/stereotypes'
require 'i18n'

module Avm
  module LocalProjects
    class Instance
      enable_simple_cache
      common_constructor :path do
        self.path = path.to_pathname
        source_stereotypes_mixins
      end

      delegate :to_s, to: :path

      def locale
        configuration.if_present(&:locale) || ::I18n.default_locale
      end

      # Backward compatibility with [EacLauncher::Paths::Logical].
      # @return [EacLauncher::Paths::Real].
      def real
        ::EacLauncher::Paths::Real.new(path.to_path)
      end

      def run_job(job, job_args = [])
        stereotypes.each { |stereotype| run_stereotype_job(stereotype, job, job_args) }
      end

      private

      # @return [Avm::Instances::Configuration]
      def configuration_uncached
        ::Avm::Instances::Configuration.find_in_path(path)
      end

      def run_stereotype_job(stereotype, job, job_args)
        job_class_method = "#{job}_class"
        if stereotype.send(job_class_method).present?
          puts stereotype.label + ": #{job} class found. Running..."
          stereotype.send(job_class_method).new(self, *job_args).run
        else
          puts stereotype.label + ": #{job} class not found"
        end
      end

      def stereotypes_uncached
        ::Avm::Projects::Stereotypes.list.select { |s| s.match?(self) }
      end

      def source_stereotypes_mixins
        stereotypes.each do |s|
          s.local_project_mixin_module.if_present { |v| singleton_class.include(v) }
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
avm-tools-0.69.0 lib/avm/local_projects/instance.rb
avm-tools-0.68.0 lib/avm/local_projects/instance.rb