Module: Axn::Core::Versioning::ClassMethods
- Defined in:
- lib/axn/core/versioning.rb
Constant Summary collapse
- VERSION_SEGMENT =
Matches a constant's final segment when it is exactly the vN convention (
V1,v2). /\Av(\d+)\z/i
Instance Method Summary collapse
-
#_tool_version_declared_here? ⇒ Boolean
True only when THIS class called
tool_versionitself — an inherited value does not count. -
#_tool_version_suffix ⇒ Object
The version number a trailing
::Vnconstant segment encodes (AgentTools::Approve::V2→ 2), or nil when the constant isn't vN-suffixed or the class is anonymous. -
#tool_version(value = NOT_SET) ⇒ Object
tool_version 2sets; zero-arg reads the effective version (1 when undeclared).
Instance Method Details
#_tool_version_declared_here? ⇒ Boolean
True only when THIS class called tool_version itself — an inherited value does not count.
Consumed by the registry's orphan guard and by tool_name's ::Vn-drop, so both treat a
::Vn class that merely inherits a version as unversioned (raise / no-drop) rather than
silently publishing it under the inherited number.
49 50 51 |
# File 'lib/axn/core/versioning.rb', line 49 def _tool_version_declared_here? instance_variable_defined?(:@_tool_version_declared) end |
#_tool_version_suffix ⇒ Object
The version number a trailing ::Vn constant segment encodes (AgentTools::Approve::V2 →
2), or nil when the constant isn't vN-suffixed or the class is anonymous. The single place
the vN suffix is parsed — consumed by the declaration-time guard below and by the registry's
enumeration guard, so the two can't drift.
57 58 59 60 |
# File 'lib/axn/core/versioning.rb', line 57 def _tool_version_suffix match = name.to_s.split("::").last&.match(VERSION_SEGMENT) match && match[1].to_i end |
#tool_version(value = NOT_SET) ⇒ Object
tool_version 2 sets; zero-arg reads the effective version (1 when undeclared).
**nil — takes no keywords at all. Without it, a lone keyword (tool_version default: true,
the removed pin option) would bind to value as a positional Hash and surface the bespoke
"must be an Integer >= 1", implying the option exists and was merely mistyped. Refusing
keywords outright yields the plain no keywords accepted a removed option should raise.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/axn/core/versioning.rb', line 30 def tool_version(value = NOT_SET, **nil) return _tool_version || 1 if value.equal?(NOT_SET) raise ArgumentError, "tool_version must be an Integer >= 1 (got #{value.inspect})" unless value.is_a?(Integer) && value >= 1 _assert_version_segment_matches!(value) self._tool_version = value # Non-inherited marker: `_tool_version` is a class_attribute (subclasses inherit its value), # so it can't answer "did THIS class declare a version?". A plain ivar on the class object # isn't inherited, so a `::V2` subclass that only inherits a parent's `tool_version 1` is # correctly seen as not-declared-here (see `_tool_version_declared_here?`). @_tool_version_declared = true value end |