babot 0.1.5 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/babot.gemspec +1 -1
  4. data/bin/babot +11 -5
  5. data/lib/babot.rb +34 -30
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb8a45434ea899ca641bf88e57fd8234f5c099f8
4
- data.tar.gz: fc78fb184612d1662a6874f036a54539bb6ec24c
3
+ metadata.gz: 3b6b19753e0a50827eb7d2423bd654a7bcecceae
4
+ data.tar.gz: 5dc21ac5617ba8b07f4e1bf413d21f995b6702be
5
5
  SHA512:
6
- metadata.gz: c7017c77bf5c724288ff87bae98191f668a756e0148dcd7b88b5f65556690cbdacbace9ca4297e34e77e89e5e7ca0da1d745d74c34cb7bde2f7ce49d37a596f4
7
- data.tar.gz: c220fc560c8faf77d4f744716f37cc8f04abc8826b71f727b84a322c7723b74ff642029d0ded1b1c184fc8e364385b804049b4367ced4d95d5aa389055684612
6
+ metadata.gz: 81c1c0a8d7fd364e5a8e0a1ab1e6c5a53f2754f4aebe69f8997d6b3c65187dfe6ee25a0daad046d30458ad457b2a57bfdf85649fc0447e2134d9d6ff58dfff16
7
+ data.tar.gz: 3be4b33f9fdf2a47e06f6749b68bc8ec39c0fb2499282e719b9516c26da8913f2eb12e7df322f35f43572231664a1ee26d4f17e43974fb8119fddbe0143d2d46
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- babot (0.1.3)
4
+ babot (0.2.1)
5
5
  activesupport
6
6
  boson
7
7
  capistrano
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'babot'
3
- s.version = '0.1.5'
3
+ s.version = '0.2.1'
4
4
  s.date = '2013-09-08'
5
5
  s.summary = "Babot"
6
6
  s.description = "A simple tool to manage Twitter bots"
data/bin/babot CHANGED
@@ -1,15 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'boson/runner'
4
- require 'pathname'
5
4
 
6
5
  $:.unshift File.expand_path("../../lib", __FILE__)
7
6
  require 'babot'
8
7
 
8
+ FileUtils.mkdir_p [Babot.root.join("config"),
9
+ Babot.root.join("bots")]
10
+
9
11
  class BabotRunner < Boson::Runner
10
- desc "Update bots"
11
- def update
12
- Babot.update
12
+ desc "Update bot [name]"
13
+ def update(name)
14
+ Babot.update(name)
13
15
  end
14
16
 
15
17
  desc "Update crontab"
@@ -31,7 +33,6 @@ class BabotRunner < Boson::Runner
31
33
  def add(name, repository)
32
34
  Babot.add name, repository
33
35
  Babot.configure name
34
- Babot.update
35
36
  end
36
37
 
37
38
  desc "Delete bot [name]"
@@ -43,6 +44,11 @@ class BabotRunner < Boson::Runner
43
44
  def configure(name)
44
45
  Babot.configure name
45
46
  end
47
+
48
+ desc "List bots"
49
+ def list
50
+ puts Babot.list
51
+ end
46
52
  end
47
53
 
48
54
  BabotRunner.start
@@ -4,34 +4,41 @@ require 'twitter'
4
4
  require 'pathname'
5
5
  require 'yaml'
6
6
  require 'tempfile'
7
+ require 'whenever'
7
8
  require 'active_support/core_ext/string/inflections'
9
+ require 'bundler/cli'
8
10
 
9
11
  class Babot
10
12
 
11
13
  class << self
12
14
 
13
- def update
14
- Dir["#{bots_root}/*"].each do |repository|
15
- Git.open(repository).pull
16
- end
15
+ def update(name)
16
+ git = Git.open(root.join("bots", name), :log => Logger.new(STDOUT))
17
+ git.fetch "origin"
18
+ git.merge "origin", "master"
19
+ system "cd #{root.join('bots', name)} && bundle install"
17
20
  end
18
21
 
19
22
  def schedule
20
- File.open(root.join("schedule.rb"), "w") do |schedule|
21
- @@config['bots'].map do |name, options|
22
- bot = instanciate name, options
23
- schedule.puts <<-eos
23
+ cron = File.open root.join("schedule.rb"), "w"
24
+ list.map { |name| instanciate(name) }.each do |bot|
25
+ cron.puts <<-eos
24
26
  every '#{bot.when}' do
25
- rake 'bots:call[#{name}]'
27
+ command 'cd #{root.join('bots', bot.name)} && bundle exec babot call #{bot.name}'
26
28
  end
27
29
  eos
28
- end
29
- Whenever::CommandLine.execute(file: schedule.path, write: true)
30
30
  end
31
+ cron.close
32
+
33
+ Whenever::CommandLine.execute(file: cron.path, write: true)
31
34
  end
32
35
 
33
36
  def add(name, repository)
34
- Git.clone repository, bot_root(name)
37
+ if repository =~ /\//
38
+ FileUtils.ln_s repository, root.join("bots", name)
39
+ else
40
+ Git.clone repository, root.join("bots", name)
41
+ end
35
42
  File.open(root.join("config", name).to_s, 'w') do |config|
36
43
  config.write({ 'consumer_key' => "",
37
44
  'consumer_secret' => "",
@@ -41,8 +48,8 @@ class Babot
41
48
  end
42
49
 
43
50
  def delete(name)
44
- FileUtils.rm_rf bot_root(name)
45
- FileUtils.rm_f config_root.join(name)
51
+ FileUtils.rm_rf root.join("bots", name)
52
+ FileUtils.rm_f root.join("config", name)
46
53
  end
47
54
 
48
55
  def configure(name)
@@ -53,14 +60,19 @@ class Babot
53
60
  Twitter.update dry(name)
54
61
  end
55
62
 
63
+ def list
64
+ Dir.entries(root.join "bots").reject { |name| name =~ /^\./ }
65
+ end
66
+
56
67
  def dry(name)
57
- instanciate(name, YAML.load_file(config_root.join name)).call
68
+ instanciate(name).call
58
69
  end
59
70
 
60
- def instanciate(name, config)
61
- require Babot.bot_root(name).join('lib', name)
71
+ def instanciate(name)
72
+ require Babot.root.join("bots", name, 'lib', name)
62
73
 
63
- Babot::const_get(name.camelize).new(name)
74
+ options = YAML.load_file(root.join("config", name))
75
+ Babot::const_get(name.camelize).new(name, options)
64
76
  rescue StandardError, ScriptError => error
65
77
  puts error, error.backtrace
66
78
  end
@@ -68,21 +80,13 @@ class Babot
68
80
  def root
69
81
  Pathname.new(ENV["HOME"]).join ".babot"
70
82
  end
83
+ end
71
84
 
72
- def bots_root
73
- root.join("bots")
74
- end
75
-
76
- def config_root
77
- root.join("config")
78
- end
85
+ attr_accessor :name
79
86
 
80
- def bot_root(name)
81
- bots_root.join name
82
- end
83
- end
87
+ def initialize(name, options)
88
+ @name = name
84
89
 
85
- def initialize(options)
86
90
  Twitter.configure do |config|
87
91
  config.consumer_key = options['consumer_key']
88
92
  config.consumer_secret = options['consumer_secret']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Goya