Sha256: 592cbe2d9cf81dac9fff7a25c2ae4285b673f47068f03d9f5a7f1104b53dc5fc

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

require 'eac_launcher/paths/real'

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

      class << self
        def from_h(context, h)
          parent_path = h[:parent_path] ? from_h(context, h[:parent_path]) : nil
          new(context, parent_path, h[:real], h[: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
        ::EacLauncher::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

3 entries across 3 versions & 1 rubygems

Version Path
eac_launcher-0.5.1 lib/eac_launcher/paths/logical.rb
eac_launcher-0.5.0 lib/eac_launcher/paths/logical.rb
eac_launcher-0.4.0 lib/eac_launcher/paths/logical.rb