do 0.2.0.g → 0.2.0.h

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/lib/do.rb CHANGED
@@ -2,6 +2,8 @@ DO_PATH = ENV['DO_PATH'] ||= File.expand_path("~/.do") unless defined?(DO_PATH)
2
2
  DO_LOGGER = $stdout unless defined?(DO_LOGGER)
3
3
  DO_LOGGER_FORMAT = "\e[36m%s\e[33m@\e[31m%s \e[33m~ \e[35m#\e[0m %s" unless defined?(DO_LOGGER_FORMAT)
4
4
 
5
+ require 'do/support'
6
+
5
7
  module DO
6
8
  autoload :CLI, 'do/cli.rb'
7
9
  autoload :Server, 'do/server.rb'
@@ -42,7 +42,7 @@ module DO
42
42
  # Set an option to the given value
43
43
  #
44
44
  def set(name, value)
45
- (class << self; self; end).send(:define_method, name) { value }
45
+ singleton_class.send(:define_method, name) { value }
46
46
  end
47
47
 
48
48
  ##
@@ -73,6 +73,9 @@ module DO
73
73
 
74
74
  def load_recipe(path)
75
75
  instance_eval(File.read(path), __FILE__, __LINE__)
76
+ rescue Exception => e
77
+ puts path
78
+ raise(e)
76
79
  end
77
80
 
78
81
  def role(name)
@@ -68,17 +68,28 @@ module DO
68
68
  # ==== Examples:
69
69
  # run 'ls -al'
70
70
  # run 'ls', '-al'
71
+ # run do |cmd|
72
+ # cmd << 'cd /mnt/www/apps'
73
+ # cmd << 'tar zxcf /tmp/backup.tar.gz project'
74
+ # end
71
75
  # run 'mysqladmin -u root -p password 'new', :input => 'oldpassword'
72
76
  #
73
- def run(*args)
77
+ def run(*args, &block)
74
78
  options = args.last.is_a?(Hash) ? args.pop : {}
79
+ { :sep => " "}.merge(options)
80
+
81
+ # If we give a block we run commands one by one
82
+ if block_given?
83
+ options.merge!(:sep => " && ")
84
+ yield args
85
+ end
75
86
 
76
87
  # Set default options if not given
77
88
  options[:pty] = request_pty unless options.has_key?(:pty)
78
89
  options[:hidden] = hidden unless options.has_key?(:hidden)
79
90
  options[:silent] = silent unless options.has_key?(:silent)
80
91
 
81
- cmd = args.join(" ")
92
+ cmd = args.join(options[:sep] || ' ')
82
93
  if options[:as]
83
94
  if options[:as] == 'root'
84
95
  cmd = "sudo #{cmd}"
@@ -140,7 +151,7 @@ module DO
140
151
  sftp.upload!(from, to, options) do |event, uploader, *args|
141
152
  case event
142
153
  when :put
143
- DO_LOGGER.print("\r" + DO_LOGGER_FORMAT % [user, name, "writing: #{args[0].local} (#{(args[1].to_f * 100 / args[0].size.to_f).to_i}%)"]); DO_LOGGER.flush
154
+ DO_LOGGER.print("\r" + DO_LOGGER_FORMAT % [user, name, "writing: #{to} (#{(args[1].to_f * 100 / args[0].size.to_f).to_i}%)"]); DO_LOGGER.flush
144
155
  when :finish
145
156
  DO_LOGGER.puts("\r" + DO_LOGGER_FORMAT % [user, name, "writing: #{to} (100%)"]); DO_LOGGER.flush
146
157
  # when :mkdir
@@ -165,7 +176,7 @@ module DO
165
176
  case event
166
177
  when :get
167
178
  size = args[0].size ? args[0].size : sftp.stat!(from).size
168
- DO_LOGGER.print("\r" + DO_LOGGER_FORMAT % [user, name, "sending: #{args[0].remote} (#{(args[1].to_f * 100 / size.to_f).to_i}%)"]); DO_LOGGER.flush
179
+ DO_LOGGER.print("\r" + DO_LOGGER_FORMAT % [user, name, "sending: #{from} (#{(args[1].to_f * 100 / size.to_f).to_i}%)"]); DO_LOGGER.flush
169
180
  when :finish
170
181
  DO_LOGGER.puts("\r" + DO_LOGGER_FORMAT % [user, name, "sending: #{from} (100%)"]); DO_LOGGER.flush
171
182
  # when :mkdir
@@ -0,0 +1,7 @@
1
+ module Kernel
2
+ def singleton_class
3
+ class << self
4
+ self
5
+ end
6
+ end unless defined?(singleton_class)
7
+ end
@@ -52,7 +52,7 @@ module DO
52
52
  if task[:in].empty?
53
53
  task[:block].arity == 1 ? task[:block].call(opts) : task[:block].call if task[:block]
54
54
  else
55
- task[:in] = send(task[:in][0]) if task[:in].size == 1 && (class << self; self; end).method_defined?(task[:in][0])
55
+ task[:in] = send(task[:in][0]) if task[:in].size == 1 && singleton_class.method_defined?(task[:in][0])
56
56
  Array(task[:in]).each do |d|
57
57
  d = d.is_a?(DO::Server) ? d.name : d
58
58
  parent = task_find(d)
@@ -64,7 +64,7 @@ module DO
64
64
  end
65
65
  end
66
66
  rescue NotFound => e
67
- (class << self; self; end).method_defined?(args_was[0]) ? send(args_was.shift) : raise(e)
67
+ singleton_class.method_defined?(args_was[0]) ? send(args_was.shift) : raise(e)
68
68
  end
69
69
  alias :run_task :task_run
70
70
 
@@ -1,3 +1,3 @@
1
1
  module DO
2
- VERSION = '0.2.0.g' unless defined?(DO::VERSION)
2
+ VERSION = '0.2.0.h' unless defined?(DO::VERSION)
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do
3
3
  version: !ruby/object:Gem::Version
4
- hash: 52
4
+ hash: 53
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 0
10
- - g
11
- version: 0.2.0.g
10
+ - h
11
+ version: 0.2.0.h
12
12
  platform: ruby
13
13
  authors:
14
14
  - Davide D'Agostino
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-01-11 00:00:00 +01:00
19
+ date: 2012-01-12 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,7 @@ files:
75
75
  - lib/do/common.rb
76
76
  - lib/do/parser.rb
77
77
  - lib/do/server.rb
78
+ - lib/do/support.rb
78
79
  - lib/do/tasks.rb
79
80
  - lib/do/utils.rb
80
81
  - lib/do/version.rb