Top Level Namespace
Defined Under Namespace
Modules: Chake
Instance Method Summary collapse
- #encrypted_for(node) ⇒ Object
- #if_files_changed(node, group_name, files) ⇒ Object
- #write_json_file(file, data) ⇒ Object
Instance Method Details
#encrypted_for(node) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/chake.rb', line 92 def encrypted_for(node) encrypted_files = Dir.glob("**/files/{default,host-#{node}}/*.{asc,gpg}") + Dir.glob("**/files/*.{asc,gpg}") encrypted_files.inject({}) do |hash, key| hash[key] = key.sub(/\.(asc|gpg)$/, '') hash end end |
#if_files_changed(node, group_name, files) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/chake.rb', line 100 def if_files_changed(node, group_name, files) if files.empty? return end hash_io = IO.popen(['xargs', 'sha1sum'], 'w+') files.sort.each { |f| hash_io.puts(f) } hash_io.close_write current_hash = hash_io.read hash_file = File.join($chake_tmpdir, node + '.' + group_name + '.sha1sum') hash_on_disk = nil if File.exists?(hash_file) hash_on_disk = File.read(hash_file) end if current_hash != hash_on_disk yield end FileUtils.mkdir_p(File.dirname(hash_file)) File.open(hash_file, 'w') do |f| f.write(current_hash) end end |
#write_json_file(file, data) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/chake.rb', line 125 def write_json_file(file, data) File.open(file, 'w') do |f| f.write(JSON.pretty_generate(data)) f.write("\n") end end |