Class: Fig::IncludeBacktrace
- Inherits:
-
Object
- Object
- Fig::IncludeBacktrace
- Defined in:
- lib/fig/include_backtrace.rb
Overview
Stack of applied “include” statements.
Keeps track of overrides and can produce package definition stack traces.
Pushing and popping actually happens via instances being held/let go by recursive method calls on RuntimeEnvironment.
Instance Attribute Summary collapse
-
#overrides ⇒ Object
readonly
Returns the value of attribute overrides.
Instance Method Summary collapse
- #add_override(statement) ⇒ Object
-
#dump(out) ⇒ Object
Prints a stack trace to the IO object.
-
#get_override(package_name, default_version = nil) ⇒ Object
Returns a version.
-
#initialize(parent, descriptor) ⇒ IncludeBacktrace
constructor
A new instance of IncludeBacktrace.
Constructor Details
#initialize(parent, descriptor) ⇒ IncludeBacktrace
Returns a new instance of IncludeBacktrace.
16 17 18 19 20 |
# File 'lib/fig/include_backtrace.rb', line 16 def initialize(parent, descriptor) @parent = parent @descriptor = descriptor @overrides = {} end |
Instance Attribute Details
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
14 15 16 |
# File 'lib/fig/include_backtrace.rb', line 14 def overrides @overrides end |
Instance Method Details
#add_override(statement) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fig/include_backtrace.rb', line 22 def add_override(statement) package_name = statement.package_name # Don't replace an existing override on the stack return if @parent && @parent.get_override(package_name) new_version = statement.version existing_version = @overrides[package_name] if existing_version && existing_version != new_version stacktrace = dump_to_string() raise Fig::RepositoryError.new( "Override #{package_name} version conflict (#{existing_version} vs #{new_version})#{statement.position_string}." + ( stacktrace.empty? ? '' : "\n#{stacktrace}" ) ) end @overrides[package_name] = new_version end |
#dump(out) ⇒ Object
Prints a stack trace to the IO object.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fig/include_backtrace.rb', line 49 def dump(out) stack = [] collect(stack) i = 0 for descriptor in stack indent='' i.times { indent += ' ' } out.puts indent + descriptor.to_string(:use_default_config, :use_description) i += 1 end end |
#get_override(package_name, default_version = nil) ⇒ Object
Returns a version.
40 41 42 43 44 45 46 |
# File 'lib/fig/include_backtrace.rb', line 40 def get_override(package_name, default_version = nil) version = @overrides[package_name] return version if version return @parent.get_override(package_name, default_version) if @parent return default_version end |