Class: Babot
- Inherits:
-
Object
- Object
- Babot
- Defined in:
- lib/babot.rb
Class Method Summary collapse
- .add(name, repository) ⇒ Object
- .cmd(command) ⇒ Object
- .configure(name) ⇒ Object
- .delete(name) ⇒ Object
- .dump ⇒ Object
- .install(dump) ⇒ Object
- .list ⇒ Object
- .push(remote) ⇒ Object
- .root ⇒ Object
- .run(name) ⇒ Object
- .run! ⇒ Object
- .schedule ⇒ Object
- .update(name) ⇒ Object
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 |
.dump ⇒ Object
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 |
.list ⇒ Object
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 |
.root ⇒ Object
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) = YAML::load_file root.join(name, "config", 'credentials.yml') Twitter.configure do |config| config.consumer_key = ['consumer_key'] config.consumer_secret = ['consumer_secret'] config.oauth_token = ['oauth_token'] config.oauth_token_secret = ['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 |
.schedule ⇒ Object
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 |