Class: Rack::ScriptStackerUtils::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/scriptstacker.rb

Instance Method Summary collapse

Constructor Details

#initialize(stacker_configs, inject_mode) ⇒ Runner

Returns a new instance of Runner.



155
156
157
158
# File 'lib/rack/scriptstacker.rb', line 155

def initialize stacker_configs, inject_mode
  @stacker_configs = stacker_configs
  @inject_mode = inject_mode
end

Instance Method Details

#replace_in_body(body, path_specs) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rack/scriptstacker.rb', line 160

def replace_in_body body, path_specs
  stackers = @stacker_configs.map do |name, config|
    [name, Stacker.new(config)]
  end.to_h

  path_specs.each do |name, specs|
    specs.each do |spec|
      stackers[name].find_files spec.source_path, spec.serve_path
    end
  end

  body.map do |chunk|
    stackers.values.reduce chunk do |memo, stacker|
      inject_into memo, stacker
    end
  end
end