Class: JsDependency::IndexCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/js_dependency/index_creator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, alias_paths: nil) ⇒ IndexCreator

Returns a new instance of IndexCreator.

Parameters:

  • src (String)
  • alias_paths (Array<String>) (defaults to: nil)


13
14
15
16
# File 'lib/js_dependency/index_creator.rb', line 13

def initialize(src, alias_paths: nil)
  @src = src
  @alias_paths = alias_paths
end

Class Method Details

.call(src, alias_paths: nil, excludes: nil) ⇒ Object

Parameters:

  • src (String)
  • alias_paths (Array<String>) (defaults to: nil)
  • excludes (Array<String>) (defaults to: nil)


21
22
23
24
25
26
# File 'lib/js_dependency/index_creator.rb', line 21

def self.call(src, alias_paths: nil, excludes: nil)
  index = new(src, alias_paths: alias_paths).call
  index.transform_values do |value|
    value.reject { |path| excludes&.any? { |exclude| path.include?(exclude) } }
  end
end

Instance Method Details

#callHash

Returns:

  • (Hash)

Raises:



29
30
31
32
33
34
35
36
37
# File 'lib/js_dependency/index_creator.rb', line 29

def call
  src_pathname = Pathname.new(@src).relative? ? Pathname.new(@src).realpath : Pathname.new(@src)
  raise Error, "#{@src} is not directory." unless src_pathname.directory?

  alias_paths = @alias_paths&.transform_values do |path|
    Pathname.new(path).relative? ? src_pathname + Pathname.new(path) : Pathname.new(path)
  end
  index_from(src_pathname, alias_paths)
end