Class: AethernalAgent::Template
- Inherits:
-
Object
- Object
- AethernalAgent::Template
- Includes:
- Errors, Filesystem
- Defined in:
- lib/aethernal_agent/template.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parsed ⇒ Object
Returns the value of attribute parsed.
-
#result ⇒ Object
Returns the value of attribute result.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Attributes included from Errors
Instance Method Summary collapse
-
#initialize(template_path, vars, options) ⇒ Template
constructor
A new instance of Template.
- #parse ⇒ Object
- #write_to(path) ⇒ Object
Methods included from Errors
Methods included from Filesystem
#aethernal_agent_file, #aethernal_agent_folder, #copy, #directory, #file_settings, #files_folder, #files_path, #home_folder_path, #meta_folder, #meta_path, #set_ownership, #set_permissions, #templates_folder, #write_template
Constructor Details
#initialize(template_path, vars, options) ⇒ Template
Returns a new instance of Template.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/aethernal_agent/template.rb', line 12 def initialize(template_path, vars, ) self.template_path = template_path self. = vars.each do |k,v| AethernalAgent.logger.debug("Setting #{k} to #{v} #{v.class}") if [String, Symbol].include?(v.class) eval("@#{k}= '#{v}'") elsif v.is_a?(NilClass) eval("@#{k}= nil") else eval("@#{k}= #{v}") end end end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
10 11 12 |
# File 'lib/aethernal_agent/template.rb', line 10 def file @file end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/aethernal_agent/template.rb', line 10 def @options end |
#parsed ⇒ Object
Returns the value of attribute parsed.
10 11 12 |
# File 'lib/aethernal_agent/template.rb', line 10 def parsed @parsed end |
#result ⇒ Object
Returns the value of attribute result.
10 11 12 |
# File 'lib/aethernal_agent/template.rb', line 10 def result @result end |
#template_path ⇒ Object
Returns the value of attribute template_path.
10 11 12 |
# File 'lib/aethernal_agent/template.rb', line 10 def template_path @template_path end |
Instance Method Details
#parse ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aethernal_agent/template.rb', line 28 def parse erb = ERB.new(File.open(self.template_path).read) self.result = erb.result(binding) if self.result self.parsed = true return true else return false end end |
#write_to(path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/aethernal_agent/template.rb', line 40 def write_to(path) return false unless self.parsed begin file = File.open(path, "w") AethernalAgent.logger.debug("Writing template to #{path}") file << self.result file.close file_settings(path, self.) rescue StandardError => e add_errors(e, path: path) return false end end |