Module: Sevgi::Graphics::Module Private

Defined in:
lib/sevgi/graphics/mixtures/call.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Callable drawing module support.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(mod, receiver, *args, **kwargs) ⇒ Object?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs module hooks and callables against a receiver.

Parameters:

  • mod (Module)

    callable module

  • receiver (Sevgi::Graphics::Element)

    receiver element

  • args (Array<Object>)

    callable arguments

  • kwargs (Hash)

    callable keyword arguments

Returns:

  • (Object, nil)

    last callable return value



52
53
54
55
56
57
58
# File 'lib/sevgi/graphics/mixtures/call.rb', line 52

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>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the methods that should be executed for a callable module.

Parameters:

  • mod (Module)

    callable module

Returns:

  • (Array<UnboundMethod>)

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a plain module



64
65
66
67
68
# File 'lib/sevgi/graphics/mixtures/call.rb', line 64

def self.callables(mod)
  ArgumentError.("Must be a module: #{mod}") unless mod.instance_of?(::Module)

  (mod.respond_to?(:_callables) ? mod._callables : mod.instance_methods).map { mod.instance_method(it) }
end

.extended(base) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Initializes callable module state.

Parameters:

  • base (Module)

    extended module



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sevgi/graphics/mixtures/call.rb', line 31

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>?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Tracks newly defined public methods as callable drawing steps.

Parameters:

  • method (Symbol)

    method name Ruby reports as added

Returns:

  • (Array<Symbol>, nil)


11
12
13
14
15
# File 'lib/sevgi/graphics/mixtures/call.rb', line 11

def method_added(method)
  super

  _callables << method if public_method_defined?(method)
end