Class: Zio::Up

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Notifications
Defined in:
lib/zio/up.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Up

Celluloid.logger = nil

Raises:



54
55
56
57
# File 'lib/zio/up.rb', line 54

def initialize(options={})
  @options = options
  raise MISSING_ARGUMENTS unless options[:dir] || options[:set]
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



48
49
50
# File 'lib/zio/up.rb', line 48

def options
  @options
end

Instance Method Details

#_pathsObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/zio/up.rb', line 72

def _paths
  return options[:set] unless options[:set].nil?
  @_paths ||= begin
    Dir.foreach(options[:dir]).map do |path|
      next if path == '.' || path == '..' || !File.exists?(File.expand_path(path, options[:dir]) + '/.git')
      ab_path = File.expand_path(path, options[:dir])
      File.directory?(ab_path) ? ab_path : nil
    end.compact
  end
end

#pull(path) ⇒ Object



67
68
69
70
# File 'lib/zio/up.rb', line 67

def pull(path)
  stdout, stderr, status = Open3.capture3("cd #{path} && git stash && git checkout master && git pull --rebase")
  publish 'up_capture_complete', [path, stdout, stderr, status]
end

#upObject



59
60
61
62
63
64
65
# File 'lib/zio/up.rb', line 59

def up
  publish 'up_paths', _paths
  _paths.each do |path|
    sleep 0.2 if options[:slow]
    self.class.new(options).async.pull(path)
  end
end