module Kind::Action::ClassMethods

Constants

ATTRIBUTE_METHODS

Public Class Methods

inherited(_) click to toggle source
# File lib/kind/action.rb, line 64
def self.inherited(_)
  raise RuntimeError, "#{self.name} is a Kind::Action and it can't be inherited"
end

Public Instance Methods

kind_action!() click to toggle source
# File lib/kind/action.rb, line 43
def kind_action!
  return self if respond_to?(:call)

  public_methods = self.public_instance_methods - ::Object.new.methods

  remaining_methods = public_methods - (__attributes__.keys + ATTRIBUTE_METHODS)

  unless remaining_methods.include?(:call!)
    raise Kind::Error.new("expected #{self} to implement `#call!`")
  end

  if remaining_methods.size > 1
    raise Kind::Error.new("#{self} can only have `#call!` as its public method")
  end

  call_parameters = public_instance_method(:call!).parameters

  unless call_parameters.empty?
    raise ArgumentError, "#{self.name}#call! must receive no arguments"
  end

  def self.inherited(_)
    raise RuntimeError, "#{self.name} is a Kind::Action and it can't be inherited"
  end

  self.send(:private_class_method, :new)

  self.class_eval(CALL_TMPL)

  self.send(:alias_method, :[], :call)
  self.send(:alias_method, :===, :call)
  self.send(:alias_method, :yield, :call)
end
to_proc() click to toggle source
# File lib/kind/action.rb, line 30
def to_proc
  @to_proc ||= ->(arg) { call(arg) }
end