class Prism::Relocation::Repository
that knows how to reparse a source and reify the values.
A repository is a configured collection of fields and a set of entries
def character_columns
Configure the character columns field for this repository and return
def character_columns field(:character_columns, CharacterColumnsField.new) end
def character_offsets
Configure the character offsets field for this repository and return
def character_offsets field(:character_offsets, CharacterOffsetsField.new) end
def code_unit_columns(encoding)
Configure the code unit columns field for this repository for a specific
def code_unit_columns(encoding) field(:code_unit_columns, CodeUnitColumnsField.new(self, encoding)) end
def code_unit_offsets(encoding)
Configure the code unit offsets field for this repository for a specific
def code_unit_offsets(encoding) field(:code_unit_offsets, CodeUnitOffsetsField.new(self, encoding)) end
def code_units_cache(encoding)
def code_units_cache(encoding) source.code_units_cache(encoding) end
def columns
def columns field(:columns, ColumnsField.new) end
def comments
Configure both the leading and trailing comment fields for this
def comments leading_comments.trailing_comments end
def enter(node_id, field_name) # :nodoc:
called from the #save* APIs.
themselves into the repository. It it internal-only and meant to be
This method is called from nodes and locations when they want to enter
def enter(node_id, field_name) # :nodoc: entry = Entry.new(self) @entries[node_id][field_name] = entry entry end
def field(name, value)
Append the given field to the repository and return the repository so
def field(name, value) raise ConfigurationError, "Cannot specify multiple #{name} fields" if @fields.key?(name) @fields[name] = value self end
def filepath
def filepath raise ConfigurationError, "Can only specify filepath for a filepath source" unless source.is_a?(SourceFilepath) field(:filepath, FilepathField.new(source.value)) end
def initialize(source)
def initialize(source) @source = source @fields = {} @entries = Hash.new { |hash, node_id| hash[node_id] = {} } end
def leading_comments
Configure the leading comments field for this repository and return
def leading_comments field(:leading_comments, LeadingCommentsField.new) end
def lines
def lines field(:lines, LinesField.new) end
def offsets
def offsets field(:offsets, OffsetsField.new) end
def reify! # :nodoc:
the various value APIs.
to reify their values. It is internal-only and meant to be called from
This method is called from the entries in the repository when they need
def reify! # :nodoc: result = source.result # Attach the comments if they have been requested as part of the # configuration of this repository. if fields.key?(:leading_comments) || fields.key?(:trailing_comments) result.attach_comments! end queue = [result.value] #: Array[Prism::node] while (node = queue.shift) @entries[node.node_id].each do |field_name, entry| value = node.public_send(field_name) values = {} #: Hash[Symbol, untyped] fields.each_value do |field| values.merge!(field.fields(value)) end entry.reify!(values) end queue.concat(node.compact_child_nodes) end @entries.clear end
def trailing_comments
Configure the trailing comments field for this repository and return
def trailing_comments field(:trailing_comments, TrailingCommentsField.new) end