Class: Babot

Inherits:
Object
  • Object
show all
Defined in:
lib/babot.rb

Class Method Summary collapse

Class Method Details

.add(name, repository) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/babot.rb', line 20

def add(name, repository)
  if repository =~ /^\//
    cmd "ln -s '#{repository}' '#{root.join(name)}'"
  else
    cmd "git clone '#{repository}' '#{root.join(name)}'"
  end
  File.open(root.join(name, "config", "credentials.yml").to_s, 'w') do |config|
    config.write({ 'consumer_key'           => "",
                   'consumer_secret'        => "",
                   'oauth_token'            => "",
                   'oauth_token_secret'     => "" }.to_yaml)
  end
end

.cmd(command) ⇒ Object



74
75
76
77
# File 'lib/babot.rb', line 74

def cmd(command)
  puts command
  system command
end

.configure(name) ⇒ Object



38
39
40
# File 'lib/babot.rb', line 38

def configure(name)
  cmd "#{ENV['EDITOR'] || 'nano'} '#{root.join(name, "config", 'credentials.yml')}'"
end

.delete(name) ⇒ Object



34
35
36
# File 'lib/babot.rb', line 34

def delete(name)
  cmd "rm -rf '#{root.join(name)}' '#{root.join(name, 'config', 'credentials.yml')}'"
end

.dumpObject



58
59
60
# File 'lib/babot.rb', line 58

def dump
  cmd "cd ~ && tar --exclude=.git -cf '#{Dir.pwd}/babot-#{Time.now.to_i}.tar' .babot"
end

.install(dump) ⇒ Object



62
63
64
# File 'lib/babot.rb', line 62

def install(dump)
  cmd "cd ~ && rm -rf '.babot' && tar -xf '#{Dir.pwd}/#{dump}'"
end

.listObject



54
55
56
# File 'lib/babot.rb', line 54

def list
  Dir.entries(root).reject { |name| name =~ /^\./ }
end

.push(remote) ⇒ Object



66
67
68
# File 'lib/babot.rb', line 66

def push(remote)
  cmd "scp -qr '#{root}' '#{remote}:~/.' && ssh '#{remote}' 'babot schedule'"
end

.rootObject



70
71
72
# File 'lib/babot.rb', line 70

def root
  Pathname.new(ENV["HOME"]).join ".babot"
end

.run(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/babot.rb', line 42

def run(name)
  options = YAML::load_file root.join(name, "config", 'credentials.yml')

  Twitter.configure do |config|
    config.consumer_key = options['consumer_key']
    config.consumer_secret = options['consumer_secret']
    config.oauth_token = options['oauth_token']
    config.oauth_token_secret = options['oauth_token_secret']
  end
  load Babot.root.join(name, 'babot.run').to_s
end

.run!Object



79
80
81
# File 'lib/babot.rb', line 79

def run!
  Twitter.update new.call
end

.scheduleObject



14
15
16
17
18
# File 'lib/babot.rb', line 14

def schedule
  list.each do |name|
    cmd "whenever -i #{name} -f #{root.join(name, 'config', 'schedule.rb')}"
  end
end

.update(name) ⇒ Object



10
11
12
# File 'lib/babot.rb', line 10

def update(name)
  cmd "cd '#{root.join(name)}' && git pull --rebase origin master && bundle install"
end