capistrano-file-transfer-ext 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,10 +22,74 @@ Add `require` line in your `Capfile` or `config/deploy.rb` or so.
22
22
 
23
23
  require "capistrano/configuration/actions/file_transfer_ext"
24
24
 
25
- `file_transfer_ext` provides following additional file transfer actions. You can use them in your tasks.
25
+ Now you can use them in your tasks.
26
+
27
+ * `safe_upload` - Transfers a file from the local host to multiple remote hosts. ([more...](#safe_upload))
28
+ * `safe_put` - Store the contents of multiple servers. ([more...](#safe_put))
29
+
30
+ ## Reference
31
+
32
+ ### `safe_upload`
33
+
34
+ **Definition**
35
+
36
+ safe_upload(from, to, options={}, &block)
37
+
38
+ **Module**
39
+
40
+ Capistrano::Configuration::Actions::FileTransferExt
41
+
42
+ The `safe_upload` acts like almost as same as `upload`, but with some little enhancements.
43
+
44
+ 1. overwrite remote file only if transmission has been successfully completed.
45
+ 2. (if you request) overwrite remote file only if the checksums are different.
46
+
47
+ #### Arguments
48
+
49
+ **from**
50
+
51
+ Thie may be either a String, or an IO object (e.g. an open file handle, or a StringIO instance).
52
+
53
+ **to**
54
+
55
+ This must be a string indicating the path on the remote server that should be uploaded to.
56
+
57
+ **options**
58
+
59
+ All of the options of `upload` are sensible. In addition, there are some extra options.
60
+
61
+ * `:install` It must be either `:always` (the default), or `:if_modified`. If `:if_modified` is given, install the file only if the checksums are different.
62
+ * `:digest` Thi is a symbol indicating which algorithm should be used to calculate the checksum of files. `:md5` is default.
63
+ * `:digest_cmd` The command to calculate checksum of files. `md5sum` is default.
64
+ * `:sudo` It must be a boolean. If set true, use `sudo` on placing files. `false` by default.
65
+
66
+
67
+ ### `safe_put`
68
+
69
+ **Definition**
70
+
71
+ safe_put(data, to, options={})
72
+
73
+ **Module**
74
+
75
+ Capistrano::Configuration::Actions::FileTransferExt
76
+
77
+ The `safe_put` action is `safe_upload`'s little brother.
78
+
79
+ #### Arguments
80
+
81
+ **data**
82
+
83
+ This is a string containing the contents of the file you want to upload.
84
+
85
+ **to**
86
+
87
+ This is a string naming the file on the remote server(s) that should be created (or overwritten) with the given data.
88
+
89
+ **options**
90
+
91
+ All of the options of `safe_upload` are sensible.
26
92
 
27
- * `safe_put` - Store the contents of multiple servers, with comparing the difference of the contents.
28
- * `safe_upload` - Transfers a file from the local host to multiple remote hosts, with comparing the difference of the contents.
29
93
 
30
94
  ## Contributing
31
95
 
@@ -20,7 +20,7 @@ module Capistrano
20
20
  }
21
21
  }
22
22
  }
23
- }.gsub(/\s+/, "").strip
23
+ }.gsub(/\s+/, "").strip
24
24
 
25
25
  def safe_put(data, path, options={})
26
26
  opts = options.dup
@@ -33,18 +33,23 @@ module Capistrano
33
33
  # The +options+ hash may include any of the following keys:
34
34
  #
35
35
  # * :transfer - use transfer_if_modified if :if_modified is set
36
- # * :place - use place_if_modified if :if_modified is set
36
+ # * :install - use install_if_modified if :if_modified is set
37
37
  # * :run_method - the default is :run.
38
38
  def safe_upload(from, to, options={}, &block)
39
39
  transfer_method = options.delete(:transfer) == :if_modified ? :transfer_if_modified : :transfer
40
- place_method = options.delete(:place) == :if_modified ? :place_if_modified : :place
40
+ if options.has_key?(:install)
41
+ install_method = options.delete(:install) == :if_modified ? :install_if_modified : :install
42
+ else
43
+ # for backward compatibility before v0.0.4.
44
+ install_method = options.delete(:place) == :if_modified ? :install_if_modified : :install
45
+ end
41
46
  run_method = ( options.delete(:run_method) || :run )
42
47
  begin
43
48
  tempname = File.join("/tmp", File.basename(to) + ".XXXXXXXXXX")
44
49
  tempfile = capture("mktemp #{tempname.dump}").strip
45
50
  run("rm -f #{tempfile.dump}", options)
46
51
  send(transfer_method, :up, from, tempfile, options, &block)
47
- send(place_method, tempfile, to, options.merge(:via => run_method), &block)
52
+ send(install_method, tempfile, to, options.merge(:via => run_method), &block)
48
53
  ensure
49
54
  run("rm -f #{tempfile.dump}", options) rescue nil
50
55
  end
@@ -92,14 +97,14 @@ module Capistrano
92
97
  end
93
98
  end
94
99
 
95
- # place a file on remote.
100
+ # install a file on remote.
96
101
  #
97
102
  # The +options+ hash may include any of the following keys:
98
103
  #
99
104
  # * :mode - permission of the file.
100
105
  # * :sudo - use sudo if set true. the default is false.
101
106
  #
102
- def place(from, to, options={}, &block)
107
+ def install(from, to, options={}, &block)
103
108
  mode = options.delete(:mode)
104
109
  try_sudo = options.delete(:sudo) ? sudo : ""
105
110
  execute = []
@@ -111,8 +116,9 @@ module Capistrano
111
116
  end
112
117
  invoke_command(execute.join(" && "), options)
113
118
  end
119
+ alias place install
114
120
 
115
- # place a file on remote, only if the destination is differ from source.
121
+ # install a file on remote, only if the destination is differ from source.
116
122
  #
117
123
  # The +options+ hash may include any of the following keys:
118
124
  #
@@ -121,7 +127,7 @@ module Capistrano
121
127
  # * :digest - digest algorithm. the default is "md5".
122
128
  # * :digest_cmd - the digest command. the default is "#{digest}sum".
123
129
  #
124
- def place_if_modified(from, to, options={}, &block)
130
+ def install_if_modified(from, to, options={}, &block)
125
131
  mode = options.delete(:mode)
126
132
  try_sudo = options.delete(:sudo) ? sudo : ""
127
133
  digest_method = options.fetch(:digest, "md5")
@@ -149,6 +155,7 @@ module Capistrano
149
155
  end
150
156
  invoke_command(execute.join(" && "), options)
151
157
  end
158
+ alias place_if_modified install_if_modified
152
159
  end
153
160
  end
154
161
  end
@@ -2,7 +2,7 @@ module Capistrano
2
2
  class Configuration
3
3
  module Actions
4
4
  module FileTransferExt
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-file-transfer-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-27 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano