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

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

Constant Summary collapse

LOCAL_MANIFEST_GLOBS =
[
  File.join("ace-handbook", ".ace-defaults", "handbook", "providers", "*.yml"),
  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.



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

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.



15
16
17
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 15

def project_root
  @project_root
end

Instance Method Details

#known?(provider) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#manifest(provider) ⇒ Object



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

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

#manifestsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ace/handbook/atoms/provider_registry.rb', line 37

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



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

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

#providersObject



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

def providers
  manifests.keys.sort
end