Module: Sevgi::Graphics::Module
- Defined in:
- lib/sevgi/graphics/mixtures/call.rb
Overview
Callable drawing module support. Extend a plain Ruby module with this API to make its public instance methods callable drawing steps.
Class Method Summary collapse
-
.call(mod, receiver, *args, **kwargs) ⇒ Object?
Runs module hooks and callables against a receiver.
-
.callables(mod) ⇒ Array<UnboundMethod>
Returns the methods that should be executed for a callable module.
-
.extended(base) ⇒ void
Initializes callable module state.
Instance Method Summary collapse
-
#method_added(method) ⇒ Array<Symbol>?
Tracks newly defined methods as callable drawing candidates.
Class Method Details
.call(mod, receiver, *args, **kwargs) ⇒ Object?
64 65 66 67 68 69 70 |
# File 'lib/sevgi/graphics/mixtures/call.rb', line 64 def self.call(mod, receiver, ...) mod._befores.each { receiver.Within(receiver, &it) } if mod.respond_to?(:_befores) && mod._befores # return last callable return value callables(mod).map { it.bind(receiver).call(...) }.last.tap do mod._afters.each { receiver.Within(receiver, &it) } if mod.respond_to?(:_afters) && mod._afters end end |
.callables(mod) ⇒ Array<UnboundMethod>
Returns the methods that should be executed for a callable module.
76 77 78 79 80 81 82 |
# File 'lib/sevgi/graphics/mixtures/call.rb', line 76 def self.callables(mod) ArgumentError.("Must be a module: #{mod}") unless mod.instance_of?(::Module) callable_names(mod).uniq.filter_map do |name| mod.instance_method(name) if mod.public_method_defined?(name) end end |
.extended(base) ⇒ void
This method returns an undefined value.
Initializes callable module state.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sevgi/graphics/mixtures/call.rb', line 42 def self.extended(base) base.instance_exec do @_callables = [] @_befores = [] @_afters = [] class << self attr_reader :_callables, :_befores, :_afters end extend(DSL) end end |
Instance Method Details
#method_added(method) ⇒ Array<Symbol>?
Tracks newly defined methods as callable drawing candidates. Invocation runs unique methods that are still public, preserving tracked definition order.
22 23 24 25 26 |
# File 'lib/sevgi/graphics/mixtures/call.rb', line 22 def method_added(method) super _callables << method if public_method_defined?(method) end |