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.



140
141
142
143
144
145
# File 'lib/rack/scriptstacker.rb', line 140

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

Instance Method Details

#replace_in_body(body, path_specs) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rack/scriptstacker.rb', line 147

def replace_in_body body, path_specs
  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