Class: Rigor::Plugin::Manifest
- Inherits:
-
Object
- Object
- Rigor::Plugin::Manifest
- Defined in:
- lib/rigor/plugin/manifest.rb
Overview
Value object describing one plugin’s identity and metadata. Constructed once per plugin class through Base.manifest; consumed by Loader when matching project configuration entries to registered plugins and by Cache::Descriptor::PluginEntry when deriving cache keys.
The fields are pinned by ADR-2 § “Registration, Configuration, and Caching”; the v0.1.0 plugin contract surface treats this struct as the public manifest shape.
Defined Under Namespace
Classes: Consumption
Constant Summary collapse
- VALID_ID =
Same regex Cache::Store::VALID_PRODUCER_ID uses, so plugin ids round-trip through cache producer ids and ‘plugin.<id>.<rule>` diagnostic identifiers without escape.
/\A[a-z][a-z0-9._-]*\z/- VALID_VALUE_KINDS =
The first-implementation ‘config_schema` accepts these value kinds. Slice 1 only checks key presence and shallow value kind; richer schemas (nested maps, enums) land later when the v0.1.0 protocol slices need them.
%i[string boolean integer array hash any].freeze
Instance Attribute Summary collapse
-
#config_schema ⇒ Object
readonly
Returns the value of attribute config_schema.
-
#consumes ⇒ Object
readonly
Returns the value of attribute consumes.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#produces ⇒ Object
readonly
Returns the value of attribute produces.
-
#protocols ⇒ Object
readonly
Returns the value of attribute protocols.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(id:, version:, description: nil, protocols: [], config_schema: {}, produces: [], consumes: []) ⇒ Manifest
constructor
rubocop:disable Metrics/ParameterLists.
- #to_h ⇒ Object
-
#validate_config(config) ⇒ Object
Validates the user-supplied plugin config block against this manifest’s ‘config_schema`.
Constructor Details
#initialize(id:, version:, description: nil, protocols: [], config_schema: {}, produces: [], consumes: []) ⇒ Manifest
rubocop:disable Metrics/ParameterLists
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rigor/plugin/manifest.rb', line 42 def initialize( # rubocop:disable Metrics/ParameterLists id:, version:, description: nil, protocols: [], config_schema: {}, produces: [], consumes: [] ) validate_id!(id) validate_version!(version) validate_protocols!(protocols) validate_config_schema!(config_schema) validate_produces!(produces) assign_fields(id, version, description, protocols, config_schema, produces, consumes) freeze end |
Instance Attribute Details
#config_schema ⇒ Object (readonly)
Returns the value of attribute config_schema.
40 41 42 |
# File 'lib/rigor/plugin/manifest.rb', line 40 def config_schema @config_schema end |
#consumes ⇒ Object (readonly)
Returns the value of attribute consumes.
40 41 42 |
# File 'lib/rigor/plugin/manifest.rb', line 40 def consumes @consumes end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
40 41 42 |
# File 'lib/rigor/plugin/manifest.rb', line 40 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
40 41 42 |
# File 'lib/rigor/plugin/manifest.rb', line 40 def id @id end |
#produces ⇒ Object (readonly)
Returns the value of attribute produces.
40 41 42 |
# File 'lib/rigor/plugin/manifest.rb', line 40 def produces @produces end |
#protocols ⇒ Object (readonly)
Returns the value of attribute protocols.
40 41 42 |
# File 'lib/rigor/plugin/manifest.rb', line 40 def protocols @protocols end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
40 41 42 |
# File 'lib/rigor/plugin/manifest.rb', line 40 def version @version end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
106 107 108 |
# File 'lib/rigor/plugin/manifest.rb', line 106 def ==(other) other.is_a?(Manifest) && to_h == other.to_h end |
#hash ⇒ Object
111 112 113 |
# File 'lib/rigor/plugin/manifest.rb', line 111 def hash to_h.hash end |
#to_h ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rigor/plugin/manifest.rb', line 94 def to_h { "id" => id, "version" => version, "description" => description, "protocols" => protocols.map(&:to_s), "config_schema" => config_schema.to_h { |k, v| [k, v.to_s] }, "produces" => produces.map(&:to_s), "consumes" => consumes.map { |c| consumption_hash(c) } } end |
#validate_config(config) ⇒ Object
Validates the user-supplied plugin config block against this manifest’s ‘config_schema`. Returns an array of human-readable error strings (empty when the config is valid). Slice 1 checks only unknown keys and shallow value kind; nested schemas come with later slices.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rigor/plugin/manifest.rb', line 76 def validate_config(config) return ["plugin config must be a Hash, got #{config.class}"] unless config.is_a?(Hash) errors = [] config.each do |key, value| key_s = key.to_s unless config_schema.key?(key_s) errors << "unknown config key #{key_s.inspect} for plugin #{id.inspect}" next end kind = config_schema.fetch(key_s) errors << "config key #{key_s.inspect} expected #{kind}, got #{value.class}" unless value_matches?(value, kind) end errors end |