Top Level Namespace

Defined Under Namespace

Modules: Chake

Instance Method Summary collapse

Instance Method Details

#encrypted_for(node) ⇒ Object



77
78
79
80
81
82
# File 'lib/chake.rb', line 77

def encrypted_for(node)
  Dir.glob("**/files/{default,host-#{node}}/*.{asc,gpg}").inject({}) do |hash, key|
    hash[key] = key.sub(/\.(asc|gpg)$/, '')
    hash
  end
end

#if_files_changed(node, group_name, files) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/chake.rb', line 84

def if_files_changed(node, group_name, files)
  if files.empty?
    return
  end
  hash = IO.popen(['sha1sum', *files]).read
  hash_file = File.join($chake_tmpdir, node + '.' + group_name + '.sha1sum')
  if !File.exists?(hash_file) || File.read(hash_file) != hash
    yield
  end
  FileUtils.mkdir_p(File.dirname(hash_file))
  File.open(hash_file, 'w') do |f|
    f.write(hash)
  end
end

#write_json_file(file, data) ⇒ Object



100
101
102
103
104
105
# File 'lib/chake.rb', line 100

def write_json_file(file, data)
  File.open(file, 'w') do |f|
    f.write(JSON.pretty_generate(data))
    f.write("\n")
  end
end