Sha256: c7eb6987e8c244c049b13ee2a3e84a9fe7aeda477c62313c557f3dc6e024aaa9

Contents?: true

Size: 1.94 KB

Versions: 9

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require 'avm/projects/stereotypes'
require 'avm/launcher/paths/real'

module Avm
  module Launcher
    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 = ::Avm::Launcher::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)
          ::Avm::Launcher::Paths::Logical.new(
            context,
            self,
            ::File.join(warped, name),
            ::File.join(logical, name)
          )
        end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
avm-tools-0.104.0 lib/avm/launcher/paths/logical.rb
avm-tools-0.103.1 lib/avm/launcher/paths/logical.rb
avm-tools-0.103.0 lib/avm/launcher/paths/logical.rb
avm-tools-0.102.2 lib/avm/launcher/paths/logical.rb
avm-tools-0.102.1 lib/avm/launcher/paths/logical.rb
avm-tools-0.102.0 lib/avm/launcher/paths/logical.rb
avm-tools-0.101.0 lib/avm/launcher/paths/logical.rb
avm-tools-0.100.0 lib/avm/launcher/paths/logical.rb
avm-tools-0.99.1 lib/avm/launcher/paths/logical.rb