Module: Superhosting::Helpers
- Included in:
- Base, ScriptExecutor::Base
- Defined in:
- lib/superhosting/helpers.rb
Instance Method Summary collapse
- #create_conf(path, conf) ⇒ Object
- #erb(node, vars) ⇒ Object
- #instance_variables_to_hash(obj) ⇒ Object
- #remove_line_from_file(path, line) ⇒ Object
- #write_if_not_exist(path, line) ⇒ Object
Instance Method Details
#create_conf(path, conf) ⇒ Object
9 10 11 |
# File 'lib/superhosting/helpers.rb', line 9 def create_conf(path, conf) File.open(path, 'w') {|f| f.write(conf) } end |
#erb(node, vars) ⇒ Object
24 25 26 27 28 |
# File 'lib/superhosting/helpers.rb', line 24 def erb(node, vars) ERB.new(node).result(OpenStruct.new(vars).instance_eval { binding }) rescue Exception => e raise NetStatus::Exception, e.net_status.merge!( message: "#{e.backtrace.first.sub! '(erb)', node._path}: #{e.message}") end |
#instance_variables_to_hash(obj) ⇒ Object
3 4 5 6 7 |
# File 'lib/superhosting/helpers.rb', line 3 def instance_variables_to_hash(obj) obj.instance_variables.map do |name| [name.to_s[1..-1].to_sym, obj.instance_variable_get(name)] end.to_h end |
#remove_line_from_file(path, line) ⇒ Object
19 20 21 22 |
# File 'lib/superhosting/helpers.rb', line 19 def remove_line_from_file(path, line) lines = File.readlines(path).select {|l| l !~ Regexp.new(line) } File.open(path, 'w') {|f| f.write lines.join('') } end |
#write_if_not_exist(path, line) ⇒ Object
13 14 15 16 17 |
# File 'lib/superhosting/helpers.rb', line 13 def write_if_not_exist(path, line) File.open(path, 'a+') do |f| f.puts(line) unless f.each_line.any? { |l| l =~ Regexp.new(line) } end end |