Module: Chef::Mixin::FromFile
- Included in:
- ApiClient, ApiClientV1, Cookbook::Metadata, DataBag, DataBagItem, Environment, Node, Provider::LWRPBase, Recipe, Resource::LWRPBase, ResourceDefinition, ResourceDefinitionList, Role, User, UserV1
- Defined in:
- lib/chef/mixin/from_file.rb
Instance Attribute Summary collapse
-
#source_file ⇒ Object
Source path from which the object was loaded.
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 Attribute Details
#source_file ⇒ Object
Source path from which the object was loaded
25 26 27 |
# File 'lib/chef/mixin/from_file.rb', line 25 def source_file @source_file end |
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.
44 45 46 47 48 49 50 51 |
# File 'lib/chef/mixin/from_file.rb', line 44 def class_from_file(filename) self.source_file = filename if File.file?(filename) && File.readable?(filename) 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.
31 32 33 34 35 36 37 38 |
# File 'lib/chef/mixin/from_file.rb', line 31 def from_file(filename) self.source_file = filename if File.file?(filename) && File.readable?(filename) instance_eval(IO.read(filename), filename, 1) else raise IOError, "Cannot open or read #{filename}!" end end |