Sha256: 20368a8876446cc66a869c314982ce4ec4ca5b66e6000c5b49e57ae8ca22046b

Contents?: true

Size: 1.79 KB

Versions: 5

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require 'avm/stereotypes'
require 'eac_launcher/paths/real'

module EacLauncher
  module Paths
    class Logical
      include ::EacRubyUtils::SimpleCache

      class << self
        def from_h(context, hash)
          parent_path = hash[:parent_path] ? from_h(context, hash[:parent_path]) : nil
          new(context, parent_path, hash[:real], hash[:logical])
        end
      end

      attr_reader :context, :real, :logical, :parent_path

      def initialize(context, parent_path, real, logical)
        @context = context
        @parent_path = parent_path
        @real = ::EacLauncher::Paths::Real.new(real)
        @logical = logical
      end

      def to_s
        logical
      end

      def to_h
        { logical: logical, real: real.to_s, parent_path: parent_path ? parent_path.to_h : nil }
      end

      def project?
        stereotypes.any?
      end

      def children
        r = []
        Dir.entries(warped).each do |c|
          c_path = ::File.join(warped, c)
          next unless ::File.directory?(c_path)
          next if c.start_with?('.')

          r << build_child(c)
        end
        r
      end

      def included?
        !context.settings.excluded_paths.include?(logical)
      end

      private

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

      def build_child(name)
        ::EacLauncher::Paths::Logical.new(
          context,
          self,
          ::File.join(warped, name),
          ::File.join(logical, name)
        )
      end

      def warped_uncached
        if is_a?(::EacLauncher::Instances::Base)
          stereotypes.each do |s|
            return s.warp_class.new(self) if s.warp_class
          end
        end
        real
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
avm-tools-0.62.1 lib/eac_launcher/paths/logical.rb
avm-tools-0.62.0 lib/eac_launcher/paths/logical.rb
avm-tools-0.61.0 lib/eac_launcher/paths/logical.rb
avm-tools-0.60.0 lib/eac_launcher/paths/logical.rb
avm-tools-0.59.0 lib/eac_launcher/paths/logical.rb