Module: Kind::Action::ClassMethods
Class Method Summary
collapse
Instance Method Summary
collapse
#__attributes__, #attribute
Class Method Details
.inherited(_) ⇒ Object
64
65
66
|
# 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
|
Instance Method Details
#kind_action! ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# 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
|
30
31
32
|
# File 'lib/kind/action.rb', line 30
def to_proc
@to_proc ||= ->(arg) { call(arg) }
end
|