Sha256: 960687105d007563fe4d7799f5962eb4db81a07b969f38497793ab6e1850f915

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require_relative "../pathname_utility"
module JsDependency
  module SourceAnalysis
    # Components have no dependencies.
    class Leave
      # @param [Hash] index
      # @param [String] src_path
      def initialize(index, src_path)
        @index = index
        @src_path = src_path
      end

      # @return [Array<String>]
      def call
        left_index = @index.filter do |_target_path, child_paths|
          blank?(child_paths)
        end

        left_index = left_index.transform_keys do |target_path|
          relative_path_or_external_path(target_path, @src_path)
        end
        left_index.keys.uniq.sort
      end

      private

      # @param [Array<String>] paths
      # @return [TrueClass, FalseClass]
      def blank?(paths)
        paths.nil? || paths.empty?
      end

      # @param [String] path
      # @param [String] src_path
      # @return [String]
      def relative_path_or_external_path(path, src_path)
        JsDependency::PathnameUtility.relative_path_or_external_path(path, src_path)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
js_dependency-0.4.1 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.4.0 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.15 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.14 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.13 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.12 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.11 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.10 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.9 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.8 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.7 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.6 lib/js_dependency/source_analysis/leave.rb
js_dependency-0.3.5 lib/js_dependency/source_analysis/leave.rb