18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/gitlab/fp/rop_helpers.rb', line 18
def retrieve_single_public_singleton_method(fp_module_or_class)
fp_class_singleton_methods = fp_module_or_class.singleton_methods(false)
public_singleton_methods = fp_class_singleton_methods - public_singleton_methods_to_ignore
return public_singleton_methods[0] if public_singleton_methods.size == 1
fp_doc_link =
"https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/remote_development/README.md#functional-patterns"
rop_doc_link =
"https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/remote_development/README.md#railway-oriented-programming-and-the-result-class"
if public_singleton_methods.size > 1
err_msg =
"Railway Oriented Programming (ROP) pattern violation in class `#{fp_module_or_class}`. " \
"Expected exactly one (1) public entry point singleton/class method to be present " \
"in a class which is used with the ROP pattern, but " \
"#{public_singleton_methods.size} " \
"public singleton methods were found: #{public_singleton_methods.sort.join(', ')}. " \
"You can make the non-entry-point method(s) private via `private_class_method :method_name`. " \
"See #{fp_doc_link} and #{rop_doc_link} for more information."
raise(ArgumentError, err_msg)
end
err_msg =
"Railway Oriented Programming (ROP) pattern violation in class `#{fp_module_or_class}`. " \
"Expected exactly one public entry point singleton/class method to be present " \
"in a class which is used with the ROP pattern, but " \
"no public singleton methods were found. " \
"See #{fp_doc_link} and #{rop_doc_link} for more information."
raise(ArgumentError, err_msg)
end
|