Class: Rigor::Plugin::Manifest

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(id:, version:, description: nil, protocols: [], config_schema: {}, produces: [], consumes: [], owns_receivers: [], type_node_resolvers: [], block_as_methods: [], heredoc_templates: [], trait_registries: [], external_files: []) ⇒ Manifest

rubocop:disable Metrics/ParameterLists



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rigor/plugin/manifest.rb', line 44

def initialize( # rubocop:disable Metrics/ParameterLists
  id:, version:,
  description: nil, protocols: [], config_schema: {},
  produces: [], consumes: [], owns_receivers: [], type_node_resolvers: [],
  block_as_methods: [], heredoc_templates: [], trait_registries: [], external_files: []
)
  validate_id!(id)
  validate_version!(version)
  validate_protocols!(protocols)
  validate_config_schema!(config_schema)
  validate_produces!(produces)
  validate_owns_receivers!(owns_receivers)
  validate_type_node_resolvers!(type_node_resolvers)
  validate_block_as_methods!(block_as_methods)
  validate_heredoc_templates!(heredoc_templates)
  validate_trait_registries!(trait_registries)
  validate_external_files!(external_files)

  assign_fields(id, version, description, protocols, config_schema, produces, consumes, owns_receivers,
                type_node_resolvers, block_as_methods, heredoc_templates, trait_registries, external_files)
  freeze
end

Instance Attribute Details

#block_as_methodsObject (readonly)

Returns the value of attribute block_as_methods.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def block_as_methods
  @block_as_methods
end

#config_schemaObject (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

#consumesObject (readonly)

Returns the value of attribute consumes.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def consumes
  @consumes
end

#descriptionObject (readonly)

Returns the value of attribute description.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def description
  @description
end

#external_filesObject (readonly)

Returns the value of attribute external_files.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def external_files
  @external_files
end

#heredoc_templatesObject (readonly)

Returns the value of attribute heredoc_templates.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def heredoc_templates
  @heredoc_templates
end

#idObject (readonly)

Returns the value of attribute id.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def id
  @id
end

#owns_receiversObject (readonly)

Returns the value of attribute owns_receivers.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def owns_receivers
  @owns_receivers
end

#producesObject (readonly)

Returns the value of attribute produces.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def produces
  @produces
end

#protocolsObject (readonly)

Returns the value of attribute protocols.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def protocols
  @protocols
end

#trait_registriesObject (readonly)

Returns the value of attribute trait_registries.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def trait_registries
  @trait_registries
end

#type_node_resolversObject (readonly)

Returns the value of attribute type_node_resolvers.



40
41
42
# File 'lib/rigor/plugin/manifest.rb', line 40

def type_node_resolvers
  @type_node_resolvers
end

#versionObject (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?



131
132
133
# File 'lib/rigor/plugin/manifest.rb', line 131

def ==(other)
  other.is_a?(Manifest) && to_h == other.to_h
end

#hashObject



136
137
138
# File 'lib/rigor/plugin/manifest.rb', line 136

def hash
  to_h.hash
end

#to_hObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rigor/plugin/manifest.rb', line 113

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) },
    "owns_receivers" => owns_receivers,
    "type_node_resolvers" => type_node_resolvers.map { |r| r.class.name },
    "block_as_methods" => block_as_methods.map(&:to_h),
    "heredoc_templates" => heredoc_templates.map(&:to_h),
    "trait_registries" => trait_registries.map(&:to_h),
    "external_files" => external_files.map(&:to_h)
  }
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.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rigor/plugin/manifest.rb', line 95

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