Class: Inspec::RequireLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/require_loader.rb

Defined Under Namespace

Classes: Item

Instance Method Summary collapse

Constructor Details

#initializeRequireLoader

Returns a new instance of RequireLoader.



9
10
11
# File 'lib/inspec/require_loader.rb', line 9

def initialize
  @contents = {}
end

Instance Method Details

#add(path, content, ref, line) ⇒ Object



13
14
15
# File 'lib/inspec/require_loader.rb', line 13

def add(path, content, ref, line)
  @contents[path] = Item.new(content, ref, line, false)
end

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/inspec/require_loader.rb', line 25

def exists?(path)
  @contents.key?(path)
end

#load(path) {|res| ... } ⇒ Object

Yields:

  • (res)


17
18
19
20
21
22
23
# File 'lib/inspec/require_loader.rb', line 17

def load(path)
  c = @contents[path]
  c.loaded = true
  res = [c.content, c.ref, c.line || 1]
  yield res if block_given?
  res
end

#loaded?(path) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/inspec/require_loader.rb', line 29

def loaded?(path)
  @contents[path].loaded == true
end