Class: Safemode::Blankslate

Inherits:
Object show all
Defined in:
lib/safemode/blankslate.rb

Direct Known Subclasses

Jail, Scope

Constant Summary collapse

@@allow_instance_methods =
['class', 'methods', 'respond_to?', 'respond_to_missing?', 'to_s', 'instance_variable_get']
@@allow_class_methods =

< needed in Rails Object#subclasses_of

['methods', 'new', 'name', '<', 'ancestors', '==']

Class Method Summary collapse

Class Method Details

.allow_class_method(*names) ⇒ Object



42
43
44
45
# File 'lib/safemode/blankslate.rb', line 42

def allow_class_method(*names)
  @allowed_class_methods = allowed_class_methods + names.map{|name| name.to_s}
  @allowed_class_methods.uniq!
end

.allow_instance_method(*names) ⇒ Object Also known as: allow



36
37
38
39
# File 'lib/safemode/blankslate.rb', line 36

def allow_instance_method(*names)
  @allowed_instance_methods = allowed_instance_methods + names.map{|name| name.to_s}
  @allowed_instance_methods.uniq!
end

.allowed_class_method?(name) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/safemode/blankslate.rb', line 52

def allowed_class_method?(name)
  allowed_class_methods.include? name.to_s
end

.allowed_class_methodsObject



32
33
34
# File 'lib/safemode/blankslate.rb', line 32

def allowed_class_methods
  @allowed_class_methods ||= []
end

.allowed_instance_method?(name) ⇒ Boolean Also known as: allowed?

Returns:

  • (Boolean)


47
48
49
# File 'lib/safemode/blankslate.rb', line 47

def allowed_instance_method?(name)
  allowed_instance_methods.include? name.to_s
end

.allowed_instance_methodsObject Also known as: allowed_methods



27
28
29
# File 'lib/safemode/blankslate.rb', line 27

def allowed_instance_methods
  @allowed_instance_methods ||= []
end

.inherited(subclass) ⇒ Object



18
19
20
# File 'lib/safemode/blankslate.rb', line 18

def inherited(subclass)
  subclass.init_allowed_methods(@allowed_instance_methods, @allowed_class_methods)
end

.init_allowed_methods(allowed_instance_methods, allowed_class_methods) ⇒ Object



22
23
24
25
# File 'lib/safemode/blankslate.rb', line 22

def init_allowed_methods(allowed_instance_methods, allowed_class_methods)
  @allowed_instance_methods = allowed_instance_methods
  @allowed_class_methods = allowed_class_methods
end

.method_added(name) ⇒ Object

ActiveSupport needs this



16
# File 'lib/safemode/blankslate.rb', line 16

def method_added(name) end