mirror of
https://github.com/inspec/inspec
synced 2024-11-24 05:33:17 +00:00
34 lines
618 B
Ruby
34 lines
618 B
Ruby
|
# encoding: utf-8
|
||
|
# author: Dominik Richter
|
||
|
# author: Christoph Hartmann
|
||
|
|
||
|
module Inspec
|
||
|
class RequireLoader
|
||
|
Item = Struct.new(:content, :ref, :line, :loaded)
|
||
|
|
||
|
def initialize
|
||
|
@contents = {}
|
||
|
end
|
||
|
|
||
|
def add(path, content, ref, line)
|
||
|
@contents[path] = Item.new(content, ref, line, false)
|
||
|
end
|
||
|
|
||
|
def load(path)
|
||
|
c = @contents[path]
|
||
|
c.loaded = true
|
||
|
res = [c.content, c.ref, c.line || 1]
|
||
|
yield res if block_given?
|
||
|
res
|
||
|
end
|
||
|
|
||
|
def exists?(path)
|
||
|
@contents.key?(path)
|
||
|
end
|
||
|
|
||
|
def loaded?(path)
|
||
|
@contents[path].loaded == true
|
||
|
end
|
||
|
end
|
||
|
end
|