Class: Inprovise::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/inprovise/resolver.rb

Overview

Script dependency Resolver for Inprovise

Author

Martin Corino

License

Distributes under the same license as Ruby

Defined Under Namespace

Classes: CircularDependencyError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, index = nil) ⇒ Resolver

Returns a new instance of Resolver.



8
9
10
11
12
13
# File 'lib/inprovise/resolver.rb', line 8

def initialize(script,index=nil)
  @script = script
  @index = index || Inprovise::ScriptIndex.default
  @last_seen = script
  @scripts = [@script]
end

Instance Attribute Details

#scriptsObject (readonly)

Returns the value of attribute scripts.



7
8
9
# File 'lib/inprovise/resolver.rb', line 7

def scripts
  @scripts
end

Instance Method Details

#resolveObject



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

def resolve
  begin
    @script.dependencies.reverse.each do |d|
      @scripts.insert(0, *Inprovise::Resolver.new(@index.get(d), @index).resolve.scripts)
    end
    @script.children.each do |c|
      child = @index.get(c)
      @scripts.concat(Inprovise::Resolver.new(child, @index).resolve.scripts) unless @scripts.include?(child)
    end
  rescue SystemStackError
    raise CircularDependencyError.new
  end
  @scripts.uniq!
  self
end