Class: Rail::Pipeline

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rail/pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Pipeline

Returns a new instance of Pipeline.



8
9
10
11
# File 'lib/rail/pipeline.rb', line 8

def initialize(config)
  @config = config
  @loader = Support::Loader.new(File.join(root, 'app/helpers/*.rb'))
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/rail/pipeline.rb', line 5

def config
  @config
end

Instance Method Details

#find(asset) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rail/pipeline.rb', line 31

def find(asset)
  paths.each do |path|
    filename = File.join(path, asset)
    return filename if File.exist?(filename)
  end
  nil
end

#process(request) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rail/pipeline.rb', line 13

def process(request)
  context = Context.new(locals: { request: request }, mixins: loader.find)

  asset = rewrite(request.path)
  klass = Processor.find(asset) or raise NotFoundError
  asset = klass.extensify(asset)
  filename = find(asset) or raise NotFoundError

  processor = klass.new(self)
  body = processor.compile(filename, context: context)

  headers = { 'Content-Type' => klass.mime_type }

  [200, headers, Array(body)]
rescue NotFoundError
  [404, {}, []]
end