class Confinement::Blobs
Attributes
file_abstraction_class[RW]
lookup[RW]
scoped_root[RW]
Public Class Methods
new(scoped_root:, file_abstraction_class:)
click to toggle source
# 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
Public Instance Methods
[](relpath)
click to toggle source
# 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!()
click to toggle source
# File lib/confinement.rb, line 353 def done! @done = true end
init(relpath, **initializer_options) { |lookup| ... }
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
files_lookup()
click to toggle source
# File lib/confinement.rb, line 390 def files_lookup @files_lookup ||= scoped_root .glob("**/*") .map { |path| [path.relative_path_from(scoped_root).to_s, path] } .to_h end
into_abspath(relpath)
click to toggle source
# File lib/confinement.rb, line 386 def into_abspath(relpath) scoped_root.concat(relpath).cleanpath end