Class: CMDx::Deprecation
- Inherits:
-
Object
- Object
- CMDx::Deprecation
- Defined in:
- lib/cmdx/deprecation.rb
Overview
Declared via ‘Task.deprecation`. Runs before a task’s lifecycle to warn, log, raise, or delegate when a task class has been marked deprecated. Supports conditional ‘:if` / `:unless` gating via Util#satisfied?.
Instance Method Summary collapse
-
#execute(task) { ... } ⇒ void
Runs the configured deprecation action, yielding first so Runtime can mark the result as deprecated for telemetry.
-
#initialize(value, options = EMPTY_HASH) ⇒ Deprecation
constructor
A new instance of Deprecation.
Constructor Details
#initialize(value, options = EMPTY_HASH) ⇒ Deprecation
Returns a new instance of Deprecation.
14 15 16 17 |
# File 'lib/cmdx/deprecation.rb', line 14 def initialize(value, = EMPTY_HASH) @value = value @options = .freeze end |
Instance Method Details
#execute(task) { ... } ⇒ void
This method returns an undefined value.
Runs the configured deprecation action, yielding first so Runtime can mark the result as deprecated for telemetry.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cmdx/deprecation.rb', line 27 def execute(task) return if @value.nil? return unless Util.satisfied?(@options[:if], @options[:unless], task) yield case @value when Symbol registry = deprecators_registry(task) if registry.key?(@value) registry.lookup(@value).call(task) else task.send(@value) end when Proc task.instance_exec(task, &@value) else return @value.call(task) if @value.respond_to?(:call) raise ArgumentError, "deprecation must be a Symbol, Proc, or respond to #call" end end |