module Laminar::Particle::InstanceMethods

Laminar::Particle instance methods.

Public Class Methods

new(context = {}) click to toggle source
# File lib/laminar/particle.rb, line 31
def initialize(context = {})
  @context = Context.build(context)
end

Public Instance Methods

call() click to toggle source
# File lib/laminar/particle.rb, line 57
def call; end
invoke() click to toggle source
# File lib/laminar/particle.rb, line 35
def invoke
  invoke!
rescue ParticleStopped
  context
end
invoke!() click to toggle source
# File lib/laminar/particle.rb, line 41
def invoke!
  begin
    run_before_callbacks
    return context if context.halted?

    param_list = context_slice
    param_list.empty? ? call : call(**context_slice)
    run_after_callbacks unless context.halted?
  rescue ParticleStopped
    run_final_callbacks
    raise
  end
  run_final_callbacks
  context
end

Private Instance Methods

context_slice() click to toggle source
# File lib/laminar/particle.rb, line 61
def context_slice
  context.select { |k, _v| introspect_params.include?(k) }
end
introspect_params() click to toggle source

Returns an array of keyword parameters that the instance expects or accepts. If the signature includes a 'splat' (:keyrest) to catch a variable set of arguments, returns the current context keys.

# File lib/laminar/particle.rb, line 68
def introspect_params
  params = self.class.instance_method(:call).parameters
  return context.keys if params.map(&:first).include?(:keyrest)

  params.map(&:last)
end