Class: Safemode::Jail
- Inherits:
-
Blankslate
- Object
- Blankslate
- Safemode::Jail
- Defined in:
- lib/safemode/jail.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(source = nil) ⇒ Jail
constructor
A new instance of Jail.
- #method_missing(method, *args, &block) ⇒ Object
- #to_jail ⇒ Object
- #to_s ⇒ Object
Methods inherited from Blankslate
allow, allowed?, allowed_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, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/safemode/jail.rb', line 15 def method_missing(method, *args, &block) unless self.class.allowed?(method) raise Safemode::NoMethodError.new(method, self.class.name, @source.class.name) end # As every call to an object in the eval'ed string will be jailed by the # parser we don't need to "proactively" jail arrays and hashes. Likewise we # don't need to jail objects returned from a jail. Doing so would provide # "double" protection, but it also would break using a return value in an if # statement, passing them to a Rails helper etc. @source.send(method, *args, &block) end |