Class: Ellipses::Server::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/ellipses/server/repository.rb

Constant Summary collapse

Error =
Class.new Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbols:, global:, directory:) ⇒ Repository

Returns a new instance of Repository.



12
13
14
15
16
17
# File 'lib/ellipses/server/repository.rb', line 12

def initialize(symbols:, global:, directory:)
  @symbols   = symbols
  @global    = global
  @root      = global.root ? ::File.join(directory, global.root) : directory
  @consumed  = Set.new
end

Instance Attribute Details

#globalObject (readonly)

Returns the value of attribute global.



10
11
12
# File 'lib/ellipses/server/repository.rb', line 10

def global
  @global
end

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/ellipses/server/repository.rb', line 10

def root
  @root
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



10
11
12
# File 'lib/ellipses/server/repository.rb', line 10

def symbols
  @symbols
end

Class Method Details

.load(directory) ⇒ Object



40
41
42
43
# File 'lib/ellipses/server/repository.rb', line 40

def load(directory)
  meta = (meta_file = MetaFile.new(directory)).read
  new symbols: Symbols.new(meta.symbols), global: meta.global, directory: meta_file.directory
end

Instance Method Details

#[](string) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/ellipses/server/repository.rb', line 19

def [](string)
  (chunks = []).tap do
    symbols.resolve(string).each { |symbol| yield_symbol(chunks, symbol) }
    next unless chunks.empty?

    raise Error, "No chunks resolved for symbol: #{string}, which may already have been consumed"
  end
end