Class: Ace::Handbook::Atoms::ProviderRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/handbook/atoms/provider_registry.rb

Constant Summary collapse

LOCAL_MANIFEST_GLOB =
File.join(
  "ace-handbook-integration-*",
  ".ace-defaults",
  "handbook",
  "providers",
  "*.yml"
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root: Ace::Handbook.project_root) ⇒ ProviderRegistry

Returns a new instance of ProviderRegistry.



20
21
22
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 20

def initialize(project_root: Ace::Handbook.project_root)
  @project_root = project_root
end

Instance Attribute Details

#project_rootObject (readonly)

Returns the value of attribute project_root.



18
19
20
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 18

def project_root
  @project_root
end

Instance Method Details

#known?(provider) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 28

def known?(provider)
  manifests.key?(provider.to_s)
end

#manifest(provider) ⇒ Object



32
33
34
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 32

def manifest(provider)
  manifests.fetch(provider.to_s)
end

#manifestsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 40

def manifests
  @manifests ||= begin
    all_paths = local_manifest_paths + installed_manifest_paths

    all_paths.each_with_object({}) do |path, manifests|
      data = YAML.safe_load_file(path, permitted_classes: [Date, Time], aliases: true) || {}
      provider = (data["provider"] || File.basename(path, ".yml")).to_s
      next if provider.empty?

      manifests[provider] ||= data.merge("_manifest_path" => path)
    end
  end
end

#output_dir(provider) ⇒ Object



36
37
38
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 36

def output_dir(provider)
  manifest(provider).fetch("output_dir")
end

#providersObject



24
25
26
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 24

def providers
  manifests.keys.sort
end