-
# frozen_string_literal: true
-
-
# Main namespace.
-
1
module Functionable
-
1
@mutex = Mutex.new
-
-
1
def self.extended descendant
-
19
descendant.singleton_class.class_eval do
-
19
def extended(*) = fail NoMethodError, "Module extend is disabled."
-
-
19
def included(*) = fail NoMethodError, "Module include is disabled."
-
-
19
def prepended(*) = fail NoMethodError, "Module prepend is disabled."
-
-
19
def module_function(*) = fail NoMethodError, "Module function behavior is disabled."
-
-
19
def public(*) = fail NoMethodError, "Public visibility is disabled."
-
-
19
def protected(*) = fail NoMethodError, "Protected visibility is disabled."
-
-
19
def private(*) = fail NoMethodError, "Private visibility is disabled, use conceal instead."
-
-
19
def conceal(*) = private_class_method(*)
-
-
19
def alias_method to, from
-
1
fail NoMethodError, "Aliasing #{from.inspect} as #{to.inspect} is disabled."
-
end
-
-
19
def class_variable_set(name, ...)
-
1
fail NoMethodError, "Setting class variable #{name.inspect} is disabled."
-
end
-
-
19
def class_variable_get name
-
1
fail NoMethodError, "Getting class variable #{name.inspect} is disabled."
-
end
-
-
19
def const_set(name, ...) = fail NoMethodError, "Setting constant #{name.inspect} is disabled."
-
-
19
def define_method(name, ...)
-
1
fail NoMethodError, "Defining method #{name.inspect} is disabled."
-
end
-
-
19
def remove_method name
-
12
then: 11
else: 1
return super if instance_variable_get :@functionable
-
-
1
fail NoMethodError, "Removing method #{name.inspect} is disabled."
-
end
-
-
19
def undef_method(name) = fail NoMethodError, "Undefining method #{name.inspect} is disabled."
-
-
19
def singleton_method_added name, allowed: %i[method_added singleton_method_added].freeze
-
50
then: 49
else: 1
return super(name) if allowed.include?(name) || instance_variable_get(:@functionable)
-
-
1
fail NoMethodError,
-
"Avoid defining #{name.inspect} as a class method because the method will be " \
-
"automatically converted to a class method for you."
-
end
-
-
19
def method_added name
-
11
unbound = instance_method name
-
-
11
instance_variable_set :@functionable, true
-
11
remove_method name
-
11
define_singleton_method name, unbound
-
11
instance_variable_set :@functionable, false
-
-
11
super
-
ensure
-
11
instance_variable_set :@functionable, false
-
end
-
end
-
end
-
-
1
def self.included(*) = fail NoMethodError, "Module include is disabled, use extend instead."
-
-
1
def self.prepended(*) = fail NoMethodError, "Module prepend is disabled, use extend instead."
-
end