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
-
#respond_to?(method) ⇒ Boolean
needed for compatibility with 1.8.7; remove this method once 1.8.7 support has been dropped.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #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 |
Instance Method Details
#respond_to?(method) ⇒ Boolean
needed for compatibility with 1.8.7; remove this method once 1.8.7 support has been dropped
29 30 31 |
# File 'lib/safemode/jail.rb', line 29 def respond_to?(method, *) respond_to_missing?(method) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
33 34 35 |
# File 'lib/safemode/jail.rb', line 33 def respond_to_missing?(method_name, include_private = false) self.class.allowed?(method_name) end |
#to_jail ⇒ Object
7 8 9 |
# File 'lib/safemode/jail.rb', line 7 def to_jail self end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/safemode/jail.rb', line 11 def to_s @source.to_s end |