Class: Confinement::Blobs

Inherits:
Object
  • Object
show all
Defined in:
lib/confinement.rb

Instance Method Summary collapse

Constructor Details

#initialize(scoped_root:, file_abstraction_class:) ⇒ Blobs

Returns a new instance of Blobs.



346
347
348
349
350
351
# File 'lib/confinement.rb', line 346

def initialize(scoped_root:, file_abstraction_class:)
  self.scoped_root = scoped_root
  self.file_abstraction_class = file_abstraction_class
  self.lookup = {}
  @done = false
end

Instance Method Details

#[](relpath) ⇒ Object



357
358
359
360
361
362
363
364
365
# File 'lib/confinement.rb', line 357

def [](relpath)
  abspath = into_abspath(relpath)

  if !lookup.key?(abspath)
    raise "Don't know about this blob: #{abspath.inspect}"
  end

  lookup[abspath]
end

#done!Object



353
354
355
# File 'lib/confinement.rb', line 353

def done!
  @done = true
end

#init(relpath, **initializer_options) {|| ... } ⇒ Object

Yields:

  • ()


367
368
369
370
371
372
373
374
# File 'lib/confinement.rb', line 367

def init(relpath, **initializer_options)
  raise "Can't add more #{file_abstraction_class}s after the initial setup!" if @done

  abspath = into_abspath(relpath)
  lookup[abspath] ||= file_abstraction_class.new(input_path: abspath, **initializer_options)
  yield lookup[abspath] if block_given?
  lookup[abspath]
end

#init_many(pattern) ⇒ Object



376
377
378
379
380
381
382
# File 'lib/confinement.rb', line 376

def init_many(pattern)
  files_lookup.filter_map do |relpath, abspath|
    if pattern.match?(relpath)
      lookup[abspath.to_s] ||= file_abstraction_class.new(input_path: abspath)
    end
  end
end