Class: CodexNotify::EnvSourceLoader::SourceSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/codex_notify/env_source_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(sources) ⇒ SourceSet

Returns a new instance of SourceSet.



16
17
18
# File 'lib/codex_notify/env_source_loader.rb', line 16

def initialize(sources)
  @sources = sources.freeze
end

Instance Method Details

#each(&block) ⇒ Object



20
21
22
# File 'lib/codex_notify/env_source_loader.rb', line 20

def each(&block)
  @sources.each(&block)
end

#excluding_kind(kind) ⇒ Object



32
33
34
# File 'lib/codex_notify/env_source_loader.rb', line 32

def excluding_kind(kind)
  self.class.new(reject { |source| source.kind == kind })
end

#lookup(key) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/codex_notify/env_source_loader.rb', line 24

def lookup(key)
  each do |source|
    value = source.values[key]
    return LookupResult.new(value:, source:) if value && !value.empty?
  end
  nil
end

#restrict_kind(kind, keys:) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/codex_notify/env_source_loader.rb', line 36

def restrict_kind(kind, keys:)
  self.class.new(map do |source|
    next source unless source.kind == kind

    Source.new(kind: source.kind, path: source.path, values: source.values.slice(*keys))
  end)
end