Module: Ridley::Mixin::FromFile
- Included in:
- Chef::Cookbook::Metadata
- Defined in:
- lib/ridley/mixin/from_file.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#class_from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object’s class.
-
#from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object.
Class Method Details
.included(base) ⇒ Object
14 15 16 |
# File 'lib/ridley/mixin/from_file.rb', line 14 def included(base) base.extend(ClassMethods) end |
Instance Method Details
#class_from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object’s class
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ridley/mixin/from_file.rb', line 42 def class_from_file(filename) filename = filename.to_s if File.exists?(filename) && File.readable?(filename) self.class_eval(IO.read(filename), filename, 1) self else raise IOError, "Could not open or read: '#{filename}'" end end |
#from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ridley/mixin/from_file.rb', line 25 def from_file(filename) filename = filename.to_s if File.exists?(filename) && File.readable?(filename) self.instance_eval(IO.read(filename), filename, 1) self else raise IOError, "Could not open or read: '#{filename}'" end end |