Class: RailsAiBridge::Registry::RegistryManifest
- Inherits:
-
Data
- Object
- Data
- RailsAiBridge::Registry::RegistryManifest
- Defined in:
- lib/rails_ai_bridge/registry/registry_manifest.rb
Overview
Immutable value object representing the root registry manifest.
Instance Attribute Summary collapse
-
#default_stack ⇒ Object
readonly
Returns the value of attribute default_stack.
-
#packs ⇒ Object
readonly
Returns the value of attribute packs.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.from_file(path) ⇒ RegistryManifest
Loads and parses a registry manifest from a JSON file on disk.
-
.from_json(hash) ⇒ RegistryManifest
Builds a RegistryManifest from a parsed JSON hash.
Instance Attribute Details
#default_stack ⇒ Object (readonly)
Returns the value of attribute 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.}" rescue SystemCallError => error raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.}" end end |
#packs ⇒ Object (readonly)
Returns the value of attribute 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.}" rescue SystemCallError => error raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.}" end end |
#version ⇒ Object (readonly)
Returns the value of attribute 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.}" rescue SystemCallError => error raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.}" end end |
Class Method Details
.from_file(path) ⇒ RegistryManifest
Loads and parses a registry manifest from a JSON file on disk.
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.}" rescue SystemCallError => error raise ArgumentError, "Registry manifest at '#{path}' could not be read: #{error.}" end |
.from_json(hash) ⇒ RegistryManifest
Builds a RailsAiBridge::Registry::RegistryManifest from a parsed JSON hash.
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 |