Class: Inprovise::Resolver
- Inherits:
-
Object
- Object
- Inprovise::Resolver
- 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
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
Instance Method Summary collapse
-
#initialize(script, index = nil) ⇒ Resolver
constructor
A new instance of Resolver.
- #resolve ⇒ Object
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
#scripts ⇒ Object (readonly)
Returns the value of attribute scripts.
7 8 9 |
# File 'lib/inprovise/resolver.rb', line 7 def scripts @scripts end |
Instance Method Details
#resolve ⇒ Object
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 |