Module: Cleanroom::ClassMethods

Defined in:
lib/cleanroom.rb

Overview

Class methods

Instance Method Summary collapse

Instance Method Details

#evaluate(instance, *args, &block) ⇒ Object

Evaluate the string or block in the context of the cleanroom.

Parameters:

  • instance (Class)

    the instance of the class to evaluate against

  • args (Array<String>)

    the args to instance_eval

  • block (Proc)

    the block to instance_eval



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.

Parameters:

  • instance (Class)

    the instance of the class to evaluate against

  • filepath (String)

    the path of the file to evaluate



53
54
55
56
57
# File 'lib/cleanroom.rb', line 53

def evaluate_file(instance, filepath)
  absolute_path = File.expand_path(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.

Parameters:

  • name (Symbol)


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_methodsHash

The list of exposed methods.

Returns:

  • (Hash)


91
92
93
# File 'lib/cleanroom.rb', line 91

def exposed_methods
  @exposed_methods ||= from_superclass(:exposed_methods, {}).dup
end