Class: Rigor::Plugin::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/plugin/manifest.rb,
sig/rigor/plugin/manifest.rbs

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, config_schema: {}, produces: [], consumes: [], owns_receivers: [], open_receivers: [], type_node_resolvers: [], block_as_methods: [], heredoc_templates: [], nested_class_templates: [], trait_registries: [], hkt_registrations: [], hkt_definitions: [], signature_paths: [], protocol_contracts: [], source_rbs_synthesizer: nil, additional_initializers: []) ⇒ Manifest

rubocop:disable Metrics/ParameterLists

Parameters:

  • id: (Object)
  • version: (Object)
  • description: (Object) (defaults to: nil)
  • config_schema: (Object) (defaults to: {})
  • produces: (Object) (defaults to: [])
  • consumes: (Object) (defaults to: [])
  • owns_receivers: (Object) (defaults to: [])
  • open_receivers: (Object) (defaults to: [])
  • type_node_resolvers: (Object) (defaults to: [])
  • block_as_methods: (Object) (defaults to: [])
  • heredoc_templates: (Object) (defaults to: [])
  • nested_class_templates: (Object) (defaults to: [])
  • trait_registries: (Object) (defaults to: [])
  • hkt_registrations: (Object) (defaults to: [])
  • hkt_definitions: (Object) (defaults to: [])
  • signature_paths: (Object) (defaults to: [])
  • protocol_contracts: (Object) (defaults to: [])
  • source_rbs_synthesizer: (Object) (defaults to: nil)
  • additional_initializers: (Object) (defaults to: [])


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rigor/plugin/manifest.rb', line 42

def initialize( # rubocop:disable Metrics/ParameterLists
  id:, version:,
  description: nil, config_schema: {},
  produces: [], consumes: [], owns_receivers: [], open_receivers: [], type_node_resolvers: [],
  block_as_methods: [], heredoc_templates: [], nested_class_templates: [],
  trait_registries: [],
  hkt_registrations: [], hkt_definitions: [], signature_paths: [], protocol_contracts: [],
  source_rbs_synthesizer: nil, additional_initializers: []
)
  validate_id!(id)
  validate_version!(version)
  validate_config_schema!(config_schema)
  validate_produces!(produces)
  validate_owns_receivers!(owns_receivers)
  validate_open_receivers!(open_receivers)
  validate_type_node_resolvers!(type_node_resolvers)
  validate_block_as_methods!(block_as_methods)
  validate_heredoc_templates!(heredoc_templates)
  validate_nested_class_templates!(nested_class_templates)
  validate_trait_registries!(trait_registries)
  validate_hkt_registrations!(hkt_registrations)
  validate_hkt_definitions!(hkt_definitions)
  validate_signature_paths!(signature_paths)
  validate_protocol_contracts!(protocol_contracts)
  validate_source_rbs_synthesizer!(source_rbs_synthesizer)
  validate_additional_initializers!(additional_initializers)

  assign_fields(id, version, description, config_schema, produces, consumes, owns_receivers,
                open_receivers, type_node_resolvers, block_as_methods, heredoc_templates, trait_registries,
                hkt_registrations, hkt_definitions, signature_paths, protocol_contracts,
                source_rbs_synthesizer)
  assign_nested_class_templates(nested_class_templates)
  assign_additional_initializers(additional_initializers)
  freeze
end

Instance Attribute Details

#additional_initializersObject (readonly)

Returns the value of attribute additional_initializers.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def additional_initializers
  @additional_initializers
end

#block_as_methodsObject (readonly)

Returns the value of attribute block_as_methods.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def block_as_methods
  @block_as_methods
end

#config_defaultsHash[String, untyped] (readonly)

Returns the value of attribute config_defaults.

Returns:

  • (Hash[String, untyped])


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def config_defaults
  @config_defaults
end

#config_schemaObject (readonly)

Returns the value of attribute config_schema.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def config_schema
  @config_schema
end

#consumesObject (readonly)

Returns the value of attribute consumes.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def consumes
  @consumes
end

#descriptionString? (readonly)

Returns the value of attribute description.

Returns:

  • (String, nil)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def description
  @description
end

#heredoc_templatesObject (readonly)

Returns the value of attribute heredoc_templates.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def heredoc_templates
  @heredoc_templates
end

#hkt_definitionsObject (readonly)

Returns the value of attribute hkt_definitions.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def hkt_definitions
  @hkt_definitions
end

#hkt_registrationsObject (readonly)

Returns the value of attribute hkt_registrations.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def hkt_registrations
  @hkt_registrations
end

#idString (readonly)

Public attribute readers (the full attr_reader surface). Plugins read manifest.id / manifest.protocol_contracts etc.; declaring them keeps the contract surface resolvable so ADR-43 ancestor resolution does not surface a false call.undefined-method on a real reader. Identity fields are typed; the structured slots stay untyped per the sparse sig/ tree.

Returns:

  • (String)


14
15
16
# File 'sig/rigor/plugin/manifest.rbs', line 14

def id
  @id
end

#nested_class_templatesObject (readonly)

Returns the value of attribute nested_class_templates.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def nested_class_templates
  @nested_class_templates
end

#open_receiversObject (readonly)

Returns the value of attribute open_receivers.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def open_receivers
  @open_receivers
end

#owns_receiversObject (readonly)

Returns the value of attribute owns_receivers.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def owns_receivers
  @owns_receivers
end

#producesObject (readonly)

Returns the value of attribute produces.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def produces
  @produces
end

#protocol_contractsObject (readonly)

Returns the value of attribute protocol_contracts.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def protocol_contracts
  @protocol_contracts
end

#signature_pathsObject (readonly)

Returns the value of attribute signature_paths.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def signature_paths
  @signature_paths
end

#source_rbs_synthesizerObject (readonly)

Returns the value of attribute source_rbs_synthesizer.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def source_rbs_synthesizer
  @source_rbs_synthesizer
end

#trait_registriesObject (readonly)

Returns the value of attribute trait_registries.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def trait_registries
  @trait_registries
end

#type_node_resolversObject (readonly)

Returns the value of attribute type_node_resolvers.

Returns:

  • (Object)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def type_node_resolvers
  @type_node_resolvers
end

#versionString (readonly)

Returns the value of attribute version.

Returns:

  • (String)


36
37
38
# File 'lib/rigor/plugin/manifest.rb', line 36

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



168
169
170
# File 'lib/rigor/plugin/manifest.rb', line 168

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

#hashInteger

Returns:

  • (Integer)


173
174
175
# File 'lib/rigor/plugin/manifest.rb', line 173

def hash
  to_h.hash
end

#to_hHash[String, untyped]

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Returns:

  • (Hash[String, untyped])


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/rigor/plugin/manifest.rb', line 143

def to_h # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  {
    "id" => id,
    "version" => version,
    "description" => description,
    "config_schema" => config_schema.to_h { |k, v| [k, v.to_s] },
    "config_defaults" => config_defaults,
    "produces" => produces.map(&:to_s),
    "consumes" => consumes.map { |c| consumption_hash(c) },
    "owns_receivers" => owns_receivers,
    "open_receivers" => open_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),
    "nested_class_templates" => nested_class_templates.map(&:to_h),
    "trait_registries" => trait_registries.map(&:to_h),
    "hkt_registrations" => hkt_registrations.map(&:to_h),
    "hkt_definitions" => hkt_definitions.map { |d| { "uri" => d.uri, "params" => d.params } },
    "signature_paths" => signature_paths,
    "protocol_contracts" => protocol_contracts.map(&:to_h),
    "source_rbs_synthesizer" => source_rbs_synthesizer&.class&.name,
    "additional_initializers" => additional_initializers.map(&:to_h)
  }
end

#validate_config(config) ⇒ Array[String]

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.

Parameters:

  • (Object)

Returns:

  • (Array[String])


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/rigor/plugin/manifest.rb', line 125

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