Class: Safemode::Jail
Instance Method Summary
collapse
Methods inherited from Blankslate
allow_class_method, allow_instance_method, allowed_class_method?, allowed_class_methods, allowed_instance_method?, allowed_instance_methods, inherited, init_allowed_methods, method_added
Constructor Details
#initialize(source = nil) ⇒ Jail
Returns a new instance of Jail.
3
4
5
|
# File 'lib/safemode/jail.rb', line 3
def initialize(source = nil)
@source = source
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/safemode/jail.rb', line 15
def method_missing(method, *args, **kwargs, &block)
if @source.is_a?(Class)
unless self.class.allowed_class_method?(method)
raise Safemode::NoMethodError.new(".#{method}", self.class.name, @source.name)
end
else
unless self.class.allowed_instance_method?(method)
raise Safemode::NoMethodError.new("##{method}", self.class.name, @source.class.name)
end
end
@source.send(method, *args, **kwargs, &block)
end
|
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
34
35
36
|
# File 'lib/safemode/jail.rb', line 34
def respond_to_missing?(method_name, include_private = false)
self.class.allowed_instance_method?(method_name)
end
|
7
8
9
|
# File 'lib/safemode/jail.rb', line 7
def to_jail
self
end
|
11
12
13
|
# File 'lib/safemode/jail.rb', line 11
def to_s
@source.to_s
end
|