joekhoobyar-capistrano-extensions 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 3
3
3
  :major: 0
4
4
  :minor: 0
@@ -2,6 +2,31 @@ require File.join(File.dirname(__FILE__), %w(files local.rb))
2
2
  require File.join(File.dirname(__FILE__), %w(files remote.rb))
3
3
 
4
4
  module CapistranoExtensions::Files
5
+
6
+ COMMANDS = [ %w(mkdir mkdir_p rmdir cp cp_r rm rm_r rm_rf
7
+ chmod chmod_R chown chown_R touch),
8
+ %w(ln ln_s ln_sf mv install) ]
9
+
10
+ FILE_TESTS = [
11
+ %w(blockdev? -b),
12
+ %w(chardev? -c),
13
+ %w(directory? -d),
14
+ %w(exists? -e),
15
+ %w(file? -f),
16
+ %w(grpowned? -G),
17
+ %w(owned? -O),
18
+ %w(pipe? -p),
19
+ %w(readable? -r),
20
+ %w(setgid? -g),
21
+ %w(setuid? -u),
22
+ %w(size? -s),
23
+ %w(socket? -S),
24
+ %w(sticky? -k),
25
+ %w(symlink? -h),
26
+ %w(writable? -w),
27
+ %w(executable? -x)
28
+ ]
29
+
5
30
  class_eval(Local.public_instance_methods(false).map do |m|
6
31
  "def #{m}(*f) send(_via.to_s + '_files').#{m}(*f) end"
7
32
  end.join("\n"))
@@ -4,6 +4,20 @@ module CapistranoExtensions
4
4
  module Files
5
5
  module Local
6
6
 
7
+ include FileUtils::Verbose
8
+
9
+ public *COMMANDS
10
+ public :pwd
11
+
12
+ FILE_TESTS.each do |m,t|
13
+ class_eval <<-EODEF
14
+ def #{m}(a, options={})
15
+ logger.trace "test #{t} \#{a.gsub ' ', '\\ '}" if logger
16
+ File.#{m} a
17
+ end
18
+ EODEF
19
+ end
20
+
7
21
  def tail_f(file, n=10)
8
22
  unless defined? File::Tail::Logfile then gem 'file-tail'; require 'file/tail' end
9
23
  File::Tail::Logfile.tail(file, :backward=>n) do |line| puts line end
@@ -12,35 +26,20 @@ module CapistranoExtensions
12
26
  end
13
27
 
14
28
  def upload(from, to)
15
- cp(from, to)
29
+ cp from, to
16
30
  end
17
31
 
18
32
  def download(from, to)
19
- cp(from, to)
20
- end
21
-
22
-
23
- include FileUtils::Verbose
24
-
25
- public *FileUtils::Verbose.methods(false)
26
- private *%w(copy_entry copy_file copy_stream
27
- remove_entry remove_entry_secure remove_file
28
- compare_file compare_stream
29
- uptodate?)
30
-
31
- def exists?(a, options={})
32
- $stdout.puts "[ -f #{_q a} ] ]"
33
- File.exists? a
34
- end
35
-
36
- def directory?(a, options={})
37
- $stdout.puts "[ -d #{_q a} ]"
38
- File.directory? a
33
+ cp from, to
39
34
  end
40
35
 
41
- def executable?(a, options={})
42
- $stdout.puts "[ -x #{_q a} ]"
43
- File.executable? a
36
+ def cd(dir, options={})
37
+ if block_given?
38
+ dir, dir2 = pwd, dir
39
+ cd dir2
40
+ yield
41
+ end
42
+ cd dir
44
43
  end
45
44
 
46
45
  end
@@ -4,6 +4,23 @@ module CapistranoExtensions
4
4
  module Files
5
5
  module Remote
6
6
 
7
+ COMMANDS = [ %w(mkdir mkdir_p rmdir cp cp_r rm rm_r rm_rf
8
+ chmod chmod_R chown chown_R touch),
9
+ %w(ln ln_s ln_sf mv install) ]
10
+
11
+ COMMANDS.each_with_index do |l,n|
12
+ l.each do |k|
13
+ k, f = k.split('_')
14
+ f = ' -' + f if f
15
+ class_eval <<-EODEF
16
+ def #{k}(a, options={})
17
+ options = args.pop if Hash === args.last
18
+ _r '#{k}#{f}', args#{', ' + (n+1).to_s if n > 0}
19
+ end
20
+ EODEF
21
+ end
22
+ end
23
+
7
24
  def tail_f(file, n=10)
8
25
  cmd = "tail -n #{n} -f #{_q file}"
9
26
  _via == :system ? system(cmd) : stream(cmd, :via => _via)
@@ -29,112 +46,17 @@ module CapistranoExtensions
29
46
  end
30
47
 
31
48
  def pwd
32
- capture("pwd", :via => _via)
33
- end
34
-
35
- def mkdir(*args)
36
- options = args.pop if Hash === args.last
37
- _r 'mkdir', args
38
- end
39
-
40
- def mkdir_p(*args)
41
- options = args.pop if Hash === args.last
42
- _r 'mkdir -p', args
43
- end
44
-
45
- def rmdir(*args)
46
- options = args.pop if Hash === args.last
47
- _r 'rmdir', args
48
- end
49
-
50
- def ln(*args)
51
- options = args.pop if Hash === args.last
52
- _r 'ln', args, 2
53
- end
54
-
55
- def ln_s(*args)
56
- options = args.pop if Hash === args.last
57
- _r 'ln -s', args, 2
58
- end
59
-
60
- def ln_sf(*args)
61
- options = args.pop if Hash === args.last
62
- _r 'ln -sf', args, 2
63
- end
64
-
65
- def cp(*args)
66
- options = args.pop if Hash === args.last
67
- _r 'cp', args
68
- end
69
-
70
- def cp_r(*args)
71
- options = args.pop if Hash === args.last
72
- _r 'cp -r', args
73
- end
74
-
75
- def mv(*args)
76
- options = args.pop if Hash === args.last
77
- _r 'mv', args, 2
78
- end
79
-
80
- def rm(*args)
81
- options = args.pop if Hash === args.last
82
- _r 'rm', args
83
- end
84
-
85
- def rm_r(*args)
86
- options = args.pop if Hash === args.last
87
- _r 'rm -r', args
88
- end
89
-
90
- def rm_rf(*args)
91
- options = args.pop if Hash === args.last
92
- _r 'rm -rf', args
93
- end
94
-
95
- def install(*args)
96
- options = args.pop if Hash === args.last
97
- _r 'install', args, 2
98
- end
99
-
100
- def chmod(*args)
101
- options = args.pop if Hash === args.last
102
- _r 'chmod', args
103
- end
104
-
105
- def chmod_R(*args)
106
- options = args.pop if Hash === args.last
107
- _r 'chmod -R', args
49
+ capture('pwd', :via => _via)
108
50
  end
109
51
 
110
- def chown(*args)
111
- options = args.pop if Hash === args.last
112
- _r 'chown', args
52
+ FILE_TESTS.each do |m,t|
53
+ class_eval <<-EODEF
54
+ def #{m}(a, options={})
55
+ _t "test #{t}", a
56
+ end
57
+ EODEF
113
58
  end
114
59
 
115
- def chown_R(*args)
116
- options = args.pop if Hash === args.last
117
- _r 'chown -R', args
118
- end
119
-
120
- def touch(*args)
121
- options = args.pop if Hash === args.last
122
- _r 'touch', args
123
- end
124
-
125
- def exists?(a)
126
- _t "test -f", a
127
- end
128
-
129
- def directory?(a, options={:verbose=>false})
130
- _t "test -d", a
131
- end
132
-
133
- def executable?(a, options={:verbose=>false})
134
- _t "test -x", a
135
- end
136
-
137
-
138
60
  private
139
61
 
140
62
  def _t(cmd, args=nil, min=nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joekhoobyar-capistrano-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Khoobyar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-24 00:00:00 -07:00
12
+ date: 2009-04-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency