Class: Fable::RuntimeObject
- Inherits:
-
Object
- Object
- Fable::RuntimeObject
- Defined in:
- lib/fable/runtime_object.rb
Direct Known Subclasses
Choice, ChoicePoint, Container, ControlCommand, Divert, Glue, NativeFunctionCall, Story, Tag, Value, VariableAssignment, VariableReference, Void
Instance Attribute Summary collapse
-
#original_object ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd.
-
#own_debug_metadata ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd.
-
#parent ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd.
-
#path ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd.
Instance Method Summary collapse
-
#compact_path_string(other_path) ⇒ Object
Find the most compact representation for a path, whether relative or global.
- #convert_path_to_relative(global_path) ⇒ Object
- #copy ⇒ Object
- #debug_line_number_of_path(path) ⇒ Object
- #debug_metadata ⇒ Object
- #indentation_string(indentation = 0) ⇒ Object
-
#initialize ⇒ RuntimeObject
constructor
A new instance of RuntimeObject.
- #resolve_path(path) ⇒ Object
- #root_content_container ⇒ Object
Constructor Details
#initialize ⇒ RuntimeObject
Returns a new instance of RuntimeObject.
7 8 9 |
# File 'lib/fable/runtime_object.rb', line 7 def initialize @path = nil end |
Instance Attribute Details
#original_object ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd
5 6 7 |
# File 'lib/fable/runtime_object.rb', line 5 def original_object @original_object end |
#own_debug_metadata ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd
5 6 7 |
# File 'lib/fable/runtime_object.rb', line 5 def @own_debug_metadata end |
#parent ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd
5 6 7 |
# File 'lib/fable/runtime_object.rb', line 5 def parent @parent end |
#path ⇒ Object
RuntimeObjects can be included in the main story as a hierarchy usually parents are container objectsd
5 6 7 |
# File 'lib/fable/runtime_object.rb', line 5 def path @path end |
Instance Method Details
#compact_path_string(other_path) ⇒ Object
Find the most compact representation for a path, whether relative or global
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/fable/runtime_object.rb', line 129 def compact_path_string(other_path) if other_path.relative? relative_path_string = other_path.components_string global_path_string = self.path.path_by_appending_path(other_path).components_string else relative_path = convert_path_to_relative(other_path) relative_path_string = relative_path.components_string global_path_string = other_path.components_string end if relative_path_string.length < global_path_string.length return relative_path_string else return global_path_string end end |
#convert_path_to_relative(global_path) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/fable/runtime_object.rb', line 88 def convert_path_to_relative(global_path) # 1. Find last shared ancestor # 2. Drill up using '..' style (actually represented as "^") # 3. Re-build downward chain from common ancestor own_path = self.path min_path_length = [global_path.length, own_path.length].min last_shared_path_comp_index = -1 (0..min_path_length).each do |i| own_component = own_path.components[i] other_component = global_path.components[i] if own_component == other_component last_shared_path_comp_index = i else break end end # No shared path components, so just use global path if last_shared_path_comp_index == -1 return global_path end number_of_upwards_moves = (own_path.length - 1) - last_shared_path_comp_index - 1 new_path_components = [] (0..number_of_upwards_moves).each do |i| new_path_components << Path::Component.parent_component end (last_shared_path_comp_index + 1..global_path.length).each do |i| new_path_components << global_path.components[i] end return Path.new(new_path_components, true) end |
#copy ⇒ Object
155 156 157 |
# File 'lib/fable/runtime_object.rb', line 155 def copy raise NotImplementedError, "#{self.class} doesn't support copying" end |
#debug_line_number_of_path(path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fable/runtime_object.rb', line 25 def debug_line_number_of_path(path) return nil if path.nil? # Try to get a line number from debug metadata root = self.root_content_container if !root.nil? target_content = root.content_at_path(path).object if !target_content.nil? = target_content. if !.nil? .start_line_number end end end end |
#debug_metadata ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/fable/runtime_object.rb', line 11 def if @own_debug_metadata.nil? if !parent.nil? return parent. || DebugMetadata.new end end return @own_debug_metadata end |
#indentation_string(indentation = 0) ⇒ Object
21 22 23 |
# File 'lib/fable/runtime_object.rb', line 21 def indentation_string(indentation = 0) " " * indentation end |
#resolve_path(path) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fable/runtime_object.rb', line 73 def resolve_path(path) if path.relative? nearest_container = self if !nearest_container.is_a?(Container) nearest_container = self.parent path = path.tail end return nearest_container.content_at_path(path) else return self.root_content_container.content_at_path(path) end end |
#root_content_container ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/fable/runtime_object.rb', line 146 def root_content_container ancestor = self while !ancestor.parent.nil? ancestor = ancestor.parent end return ancestor end |