Class: RailsAiBridge::Registry::RegistryManifest

Inherits:
Data
  • Object
show all
Defined in:
lib/rails_ai_bridge/registry/registry_manifest.rb

Overview

Immutable value object representing the root registry manifest.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#default_stackObject (readonly)

Returns the value of attribute default_stack

Returns:

  • (Object)

    the current value of default_stack



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_ai_bridge/registry/registry_manifest.rb', line 13

RegistryManifest = Data.define(:version, :packs, :default_stack) do
  # Builds a {RegistryManifest} from a parsed JSON hash.
  #
  # @param hash [Hash] parsed JSON object
  # @return [RegistryManifest]
  def self.from_json(hash)
    packs = (hash['packs'] || {}).transform_values do |pack_hash|
      PackDefinition.new(
        source: pack_hash.fetch('source'),
        tile: pack_hash.fetch('tile', 'directory.json'),
        always_loaded: pack_hash.fetch('always_loaded', false),
        depends_on: pack_hash.fetch('depends_on', []),
        ref: pack_hash.fetch('ref', nil)
      )
    end

    new(
      version: hash.fetch('version'),
      packs: packs,
      default_stack: hash.fetch('default_stack', [])
    )
  rescue KeyError => error
    raise ArgumentError, "Registry manifest missing required field: #{error.key}"
  end

  # Loads and parses a registry manifest from a JSON file on disk.
  #
  # @param path [String] absolute or relative path to the registry JSON file
  # @return [RegistryManifest]
  # @raise [ArgumentError] if the file does not exist, cannot be read, or contains malformed JSON
  def self.from_file(path)
    from_json(JSON.parse(File.read(path)))
  rescue JSON::ParserError => error
    raise ArgumentError, "Registry manifest at '#{path}' contains invalid JSON: #{error.message}"
  rescue SystemCallError => error
    raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.message}"
  end
end

#packsObject (readonly)

Returns the value of attribute packs

Returns:

  • (Object)

    the current value of packs



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_ai_bridge/registry/registry_manifest.rb', line 13

RegistryManifest = Data.define(:version, :packs, :default_stack) do
  # Builds a {RegistryManifest} from a parsed JSON hash.
  #
  # @param hash [Hash] parsed JSON object
  # @return [RegistryManifest]
  def self.from_json(hash)
    packs = (hash['packs'] || {}).transform_values do |pack_hash|
      PackDefinition.new(
        source: pack_hash.fetch('source'),
        tile: pack_hash.fetch('tile', 'directory.json'),
        always_loaded: pack_hash.fetch('always_loaded', false),
        depends_on: pack_hash.fetch('depends_on', []),
        ref: pack_hash.fetch('ref', nil)
      )
    end

    new(
      version: hash.fetch('version'),
      packs: packs,
      default_stack: hash.fetch('default_stack', [])
    )
  rescue KeyError => error
    raise ArgumentError, "Registry manifest missing required field: #{error.key}"
  end

  # Loads and parses a registry manifest from a JSON file on disk.
  #
  # @param path [String] absolute or relative path to the registry JSON file
  # @return [RegistryManifest]
  # @raise [ArgumentError] if the file does not exist, cannot be read, or contains malformed JSON
  def self.from_file(path)
    from_json(JSON.parse(File.read(path)))
  rescue JSON::ParserError => error
    raise ArgumentError, "Registry manifest at '#{path}' contains invalid JSON: #{error.message}"
  rescue SystemCallError => error
    raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.message}"
  end
end

#versionObject (readonly)

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_ai_bridge/registry/registry_manifest.rb', line 13

RegistryManifest = Data.define(:version, :packs, :default_stack) do
  # Builds a {RegistryManifest} from a parsed JSON hash.
  #
  # @param hash [Hash] parsed JSON object
  # @return [RegistryManifest]
  def self.from_json(hash)
    packs = (hash['packs'] || {}).transform_values do |pack_hash|
      PackDefinition.new(
        source: pack_hash.fetch('source'),
        tile: pack_hash.fetch('tile', 'directory.json'),
        always_loaded: pack_hash.fetch('always_loaded', false),
        depends_on: pack_hash.fetch('depends_on', []),
        ref: pack_hash.fetch('ref', nil)
      )
    end

    new(
      version: hash.fetch('version'),
      packs: packs,
      default_stack: hash.fetch('default_stack', [])
    )
  rescue KeyError => error
    raise ArgumentError, "Registry manifest missing required field: #{error.key}"
  end

  # Loads and parses a registry manifest from a JSON file on disk.
  #
  # @param path [String] absolute or relative path to the registry JSON file
  # @return [RegistryManifest]
  # @raise [ArgumentError] if the file does not exist, cannot be read, or contains malformed JSON
  def self.from_file(path)
    from_json(JSON.parse(File.read(path)))
  rescue JSON::ParserError => error
    raise ArgumentError, "Registry manifest at '#{path}' contains invalid JSON: #{error.message}"
  rescue SystemCallError => error
    raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.message}"
  end
end

Class Method Details

.from_file(path) ⇒ RegistryManifest

Loads and parses a registry manifest from a JSON file on disk.

Parameters:

  • path (String)

    absolute or relative path to the registry JSON file

Returns:

Raises:

  • (ArgumentError)

    if the file does not exist, cannot be read, or contains malformed JSON



43
44
45
46
47
48
49
# File 'lib/rails_ai_bridge/registry/registry_manifest.rb', line 43

def self.from_file(path)
  from_json(JSON.parse(File.read(path)))
rescue JSON::ParserError => error
  raise ArgumentError, "Registry manifest at '#{path}' contains invalid JSON: #{error.message}"
rescue SystemCallError => error
  raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.message}"
end

.from_json(hash) ⇒ RegistryManifest

Builds a RailsAiBridge::Registry::RegistryManifest from a parsed JSON hash.

Parameters:

  • hash (Hash)

    parsed JSON object

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rails_ai_bridge/registry/registry_manifest.rb', line 18

def self.from_json(hash)
  packs = (hash['packs'] || {}).transform_values do |pack_hash|
    PackDefinition.new(
      source: pack_hash.fetch('source'),
      tile: pack_hash.fetch('tile', 'directory.json'),
      always_loaded: pack_hash.fetch('always_loaded', false),
      depends_on: pack_hash.fetch('depends_on', []),
      ref: pack_hash.fetch('ref', nil)
    )
  end

  new(
    version: hash.fetch('version'),
    packs: packs,
    default_stack: hash.fetch('default_stack', [])
  )
rescue KeyError => error
  raise ArgumentError, "Registry manifest missing required field: #{error.key}"
end