Class: JsDependency::IndexCreator
- Inherits:
-
Object
- Object
- JsDependency::IndexCreator
- Defined in:
- lib/js_dependency/index_creator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Hash
-
#initialize(src, alias_paths: nil) ⇒ IndexCreator
constructor
A new instance of IndexCreator.
Constructor Details
#initialize(src, alias_paths: nil) ⇒ IndexCreator
Returns a new instance of IndexCreator.
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
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
#call ⇒ Hash
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 |