class Prism::Relocation::Repository

A repository is a configured collection of fields and a set of entries that knows how to reparse a source and reify the values.

Attributes

entries[R]

The entries that have been saved on this repository.

fields[R]

The fields that have been configured on this repository.

source[R]

The source associated with this repository. This will be either a SourceFilepath (the most common use case) or a SourceString.

Public Class Methods

new(source) click to toggle source

Initialize a new repository with the given source.

# File prism/relocation.rb, line 369
def initialize(source)
  @source = source
  @fields = {}
  @entries = Hash.new { |hash, node_id| hash[node_id] = {} }
end

Public Instance Methods

character_columns() click to toggle source

Configure the character columns field for this repository and return self.

# File prism/relocation.rb, line 415
def character_columns
  field(:character_columns, CharacterColumnsField.new)
end
character_offsets() click to toggle source

Configure the character offsets field for this repository and return self.

# File prism/relocation.rb, line 398
def character_offsets
  field(:character_offsets, CharacterOffsetsField.new)
end
code_unit_columns(encoding) click to toggle source

Configure the code unit columns field for this repository for a specific encoding and return self.

# File prism/relocation.rb, line 421
def code_unit_columns(encoding)
  field(:code_unit_columns, CodeUnitColumnsField.new(self, encoding))
end
code_unit_offsets(encoding) click to toggle source

Configure the code unit offsets field for this repository for a specific encoding and return self.

# File prism/relocation.rb, line 404
def code_unit_offsets(encoding)
  field(:code_unit_offsets, CodeUnitOffsetsField.new(self, encoding))
end
code_units_cache(encoding) click to toggle source

Create a code units cache for the given encoding from the source.

# File prism/relocation.rb, line 376
def code_units_cache(encoding)
  source.code_units_cache(encoding)
end
columns() click to toggle source

Configure the columns field for this repository and return self.

# File prism/relocation.rb, line 409
def columns
  field(:columns, ColumnsField.new)
end
comments() click to toggle source

Configure both the leading and trailing comment fields for this repository and return self.

# File prism/relocation.rb, line 439
def comments
  leading_comments.trailing_comments
end
filepath() click to toggle source

Configure the filepath field for this repository and return self.

# File prism/relocation.rb, line 381
def filepath
  raise ConfigurationError, "Can only specify filepath for a filepath source" unless source.is_a?(SourceFilepath)
  field(:filepath, FilepathField.new(source.value))
end
leading_comments() click to toggle source

Configure the leading comments field for this repository and return self.

# File prism/relocation.rb, line 427
def leading_comments
  field(:leading_comments, LeadingCommentsField.new)
end
lines() click to toggle source

Configure the lines field for this repository and return self.

# File prism/relocation.rb, line 387
def lines
  field(:lines, LinesField.new)
end
offsets() click to toggle source

Configure the offsets field for this repository and return self.

# File prism/relocation.rb, line 392
def offsets
  field(:offsets, OffsetsField.new)
end
trailing_comments() click to toggle source

Configure the trailing comments field for this repository and return self.

# File prism/relocation.rb, line 433
def trailing_comments
  field(:trailing_comments, TrailingCommentsField.new)
end

Private Instance Methods

field(name, value) click to toggle source

Append the given field to the repository and return the repository so that these calls can be chained.

# File prism/relocation.rb, line 487
def field(name, value)
  raise ConfigurationError, "Cannot specify multiple #{name} fields" if @fields.key?(name)
  @fields[name] = value
  self
end