Module: Metis::Mixin::FromFile
- Included in:
- CheckDefinitionList, Configuration
- Defined in:
- lib/metis/mixin/from_file.rb
Instance Method Summary collapse
-
#class_from_file(filename) ⇒ Object
Loads a given ruby file, and runs class_eval against it in the context of the current object.
-
#from_file(filename) ⇒ Object
Loads a given ruby file, and runs instance_eval against it in the context of the current object.
Instance Method Details
#class_from_file(filename) ⇒ Object
Loads a given ruby file, and runs class_eval against it in the context of the current object.
Raises an IOError if the file cannot be found, or is not readable.
21 22 23 24 25 26 27 |
# File 'lib/metis/mixin/from_file.rb', line 21 def class_from_file(filename) if File.exists?(filename) && File.readable?(filename) self.class_eval(IO.read(filename), filename, 1) else raise IOError, "Cannot open or read #{filename}!" end end |
#from_file(filename) ⇒ Object
Loads a given ruby file, and runs instance_eval against it in the context of the current object.
Raises an IOError if the file cannot be found, or is not readable.
9 10 11 12 13 14 15 |
# File 'lib/metis/mixin/from_file.rb', line 9 def from_file(filename) if File.exists?(filename) && File.readable?(filename) self.instance_eval(IO.read(filename), filename, 1) else raise IOError, "Cannot open or read #{filename}!" end end |