Module: Cleanroom::ClassMethods
- Defined in:
- lib/cleanroom.rb
Overview
Class methods
Instance Method Summary collapse
-
#evaluate(instance, *args, &block) ⇒ Object
Evaluate the string or block in the context of the cleanroom.
-
#evaluate_file(instance, filepath) ⇒ Object
Evaluate the file in the context of the cleanroom.
-
#expose(name) ⇒ Object
Expose the given method to the DSL.
-
#exposed_methods ⇒ Hash
The list of exposed methods.
Instance Method Details
#evaluate(instance, *args, &block) ⇒ Object
Evaluate the string or block in the context of the cleanroom.
69 70 71 |
# File 'lib/cleanroom.rb', line 69 def evaluate(instance, *args, &block) cleanroom.new(instance).instance_eval(*args, &block) end |
#evaluate_file(instance, filepath) ⇒ Object
Evaluate the file in the context of the cleanroom.
53 54 55 56 57 |
# File 'lib/cleanroom.rb', line 53 def evaluate_file(instance, filepath) absolute_path = File.(filepath) file_contents = IO.read(absolute_path) evaluate(instance, file_contents, absolute_path, 1) end |
#expose(name) ⇒ Object
Expose the given method to the DSL.
78 79 80 81 82 83 84 |
# File 'lib/cleanroom.rb', line 78 def expose(name) unless public_method_defined?(name) raise NameError, "undefined method `#{name}' for class `#{self.name}'" end exposed_methods[name] = true end |
#exposed_methods ⇒ Hash
The list of exposed methods.
91 92 93 |
# File 'lib/cleanroom.rb', line 91 def exposed_methods @exposed_methods ||= from_superclass(:exposed_methods, {}).dup end |