dotfiles 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ require 'json'
3
3
  require 'uri'
4
4
  require 'net/http'
5
5
  require 'digest'
6
+ require 'fileutils'
6
7
 
7
8
  require 'dot_files/errors'
8
9
  require 'dot_files/config'
@@ -113,6 +113,14 @@ module DotFiles
113
113
  req = request("save", :data => {:dot_file => {:path => path, :file => contents}})
114
114
  req ? true : false
115
115
  end
116
+
117
+ def save_local_file(filename, contents)
118
+ local_path = File.join(ENV['HOME'], filename)
119
+ FileUtils.mkdir_p(File.dirname(local_path))
120
+ File.open(local_path, 'w') { |f| f.write(contents) }
121
+ DotFiles.config.shas[filename] = Digest::SHA1.hexdigest(contents)
122
+ DotFiles.config.save
123
+ end
116
124
 
117
125
  private
118
126
 
@@ -41,10 +41,8 @@ command :sync do
41
41
  puts "{{downloading}} #{file[:filename]}"
42
42
  contents = remote_file_contents(file[:filename])
43
43
  puts "{{saving}} #{file[:filename]}"
44
- local_path = File.join(ENV['HOME'], file[:filename])
45
- File.open(local_path, 'w') { |f| f.write(contents) }
46
- puts "{{saved}} #{contents.size.to_s} bytes to #{local_path}"
47
- DotFiles.config.shas[file[:filename]] = Digest::SHA1.hexdigest(contents)
44
+ save_local_file(file[:filename], contents)
45
+ puts "{{saved}} #{contents.size.to_s} bytes to #{file[:filename]}"
48
46
  when :update_remote
49
47
  puts "{{uploading}} #{file[:filename]}"
50
48
  local_path = File.join(ENV['HOME'], file[:filename])
@@ -79,12 +77,9 @@ desc 'Pull a remote file to your local file system'
79
77
  usage 'pull path/to/dotfile'
80
78
  command :pull do |path|
81
79
  filename = path.gsub(/\A#{ENV['HOME']}\//, '')
82
- local_path = File.join(ENV['HOME'], filename)
83
80
  if contents = remote_file_contents(filename)
84
- File.open(local_path, 'w') { |f| f.write(contents) }
85
- DotFiles.config.shas[filename] = Digest::SHA1.hexdigest(contents)
86
- DotFiles.config.save
87
- puts "Downloaded #{contents.size} bytes to #{local_path}."
81
+ save_local_file(filename, contents)
82
+ puts "Downloaded #{contents.size} bytes to #{filename}."
88
83
  else
89
84
  error "Couldn't download remote file from '#{filename}'. Does it exist?"
90
85
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 3
9
- version: 1.0.3
8
+ - 4
9
+ version: 1.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Cooke