cory-rubyflashbake 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/License.txt +22 -0
- data/README.rdoc +7 -0
- data/README.textile +38 -0
- data/bin/rubyflashbake +27 -0
- data/lib/data/.rubyflashbake_example +73 -0
- data/lib/rubyflashbake/core.rb +170 -0
- data/lib/rubyflashbake/options.rb +50 -0
- data/lib/rubyflashbake/plugins/internet.rb +19 -0
- data/lib/rubyflashbake/plugins/location.rb +25 -0
- data/lib/rubyflashbake/plugins/time.rb +13 -0
- data/lib/rubyflashbake/plugins/twitter.rb +23 -0
- data/lib/rubyflashbake/plugins/weather.rb +20 -0
- data/spec/rspec_suite.rb +10 -0
- data/spec/rubyflashbake/core_spec.rb +280 -0
- data/spec/rubyflashbake/options_spec.rb +90 -0
- data/spec/rubyflashbake/plugins/internet_spec.rb +34 -0
- data/spec/rubyflashbake/plugins/location_spec.rb +37 -0
- data/spec/rubyflashbake/plugins/time_spec.rb +21 -0
- data/spec/rubyflashbake/plugins/twitter_spec.rb +35 -0
- data/spec/rubyflashbake/plugins/weather_spec.rb +41 -0
- data/spec/rubyflashbake/testdata/testdir/.gitignore +3 -0
- metadata +73 -0
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008-2009 Cory Ondrejka
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/README.textile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
h1. RubyFlashbake
|
2
|
+
|
3
|
+
A Ruby project inspired by Thomas Gideon's python "Flashbake":http://wiki.github.com/commandline/flashbake project.
|
4
|
+
|
5
|
+
h2. What it is
|
6
|
+
|
7
|
+
A set of routines to help with writing and blogging.
|
8
|
+
|
9
|
+
h2. "But, why?" you ask
|
10
|
+
|
11
|
+
I thought that Flashbake was a very cool project, but since I spend time in the Ruby world - and do more blogging than writing - converting it to Ruby seemed like a fun weekend project. Plus, I wanted to experiment with monitoring directories, building an app that works well with small Ruby plugins, and do some web scraping.
|
12
|
+
|
13
|
+
As always, it's all about writing snippets of fun code.
|
14
|
+
|
15
|
+
h2. License
|
16
|
+
|
17
|
+
Copyright (c) 2009 Cory Ondrejka
|
18
|
+
|
19
|
+
Permission is hereby granted, free of charge, to any person
|
20
|
+
obtaining a copy of this software and associated documentation
|
21
|
+
files (the "Software"), to deal in the Software without
|
22
|
+
restriction, including without limitation the rights to use,
|
23
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
24
|
+
copies of the Software, and to permit persons to whom the
|
25
|
+
Software is furnished to do so, subject to the following
|
26
|
+
conditions:
|
27
|
+
|
28
|
+
The above copyright notice and this permission notice shall be
|
29
|
+
included in all copies or substantial portions of the Software.
|
30
|
+
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
32
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
33
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
34
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
35
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
36
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
37
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
38
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/rubyflashbake
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# ruby-flashbake
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
require "#{File.dirname(__FILE__)}/../lib/rubyflashbake/options"
|
8
|
+
require "#{File.dirname(__FILE__)}/../lib/rubyflashbake/core"
|
9
|
+
|
10
|
+
# startup and read configuration
|
11
|
+
options = RubyFlashbakeOptions.new(ARGV)
|
12
|
+
|
13
|
+
# if options read successfull, go read configuration file
|
14
|
+
rfb = RubyFlashbake.new
|
15
|
+
rfb.load_file(options.config_file)
|
16
|
+
rfb.configure_git(Dir.pwd)
|
17
|
+
rfb.configure_github(Dir.pwd)
|
18
|
+
rfb.load_plugins
|
19
|
+
rfb.setup_watch_commits(Dir.pwd)
|
20
|
+
puts "startup commit and push"
|
21
|
+
rfb.git_commit(Dir.pwd, rfb.checkin_comment)
|
22
|
+
rfb.start_directory_watchers
|
23
|
+
puts "hit return to stop watching directory"
|
24
|
+
gets
|
25
|
+
rfb.stop_directory_watchers
|
26
|
+
puts "exit commit and push"
|
27
|
+
rfb.git_commit(Dir.pwd, rfb.checkin_comment)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# default rubyflashbake config file should be .rubyflashbake in the local directory
|
2
|
+
# stored in the RubyFlashbake.status instance hash
|
3
|
+
# rubyflashbake expects valid yaml
|
4
|
+
|
5
|
+
# plugin directories are relative to ./lib/rubyflashbake directory
|
6
|
+
# you can add more than one if you want
|
7
|
+
:PLUGIN_DIRECTORIES:
|
8
|
+
- plugins
|
9
|
+
|
10
|
+
# when modifying git repository, spam STDOUT
|
11
|
+
:VERBOSE: true
|
12
|
+
|
13
|
+
# what order should we run plugins in?
|
14
|
+
:PLUGIN_CALL_ORDER:
|
15
|
+
- :TIME
|
16
|
+
- :INTERNET
|
17
|
+
- :LOCATION
|
18
|
+
- :WEATHER
|
19
|
+
- :TWITTER
|
20
|
+
|
21
|
+
# plugins take the form of
|
22
|
+
# :PLUGINBASENAME:
|
23
|
+
# - :ACTIVE: boolean to turn plugin on and off
|
24
|
+
# - optional hash of configuration arguments
|
25
|
+
# convetion for plugins:
|
26
|
+
# be name.rb
|
27
|
+
# map to a ALLCAPS(name) section in this file
|
28
|
+
# require a do_name function called every time a file is saved
|
29
|
+
# have an optional configure_name functions called once on configuration file load
|
30
|
+
|
31
|
+
# internet alive plugin, confirmed by pinging a test uri
|
32
|
+
:PLUGIN:
|
33
|
+
:INTERNET:
|
34
|
+
:ACTIVE: true
|
35
|
+
:OPTIONAL_HASH:
|
36
|
+
:INTERNET_ALIVE: false
|
37
|
+
:INTERNET_TEST_URI: www.google.com
|
38
|
+
|
39
|
+
# location plugin, using maxmind's javascript api
|
40
|
+
:LOCATION:
|
41
|
+
:ACTIVE: true
|
42
|
+
|
43
|
+
# time plugin, just using native Ruby Time class
|
44
|
+
:TIME:
|
45
|
+
:ACTIVE: true
|
46
|
+
|
47
|
+
# twitter plugin, using twitter's rest API
|
48
|
+
:TWITTER:
|
49
|
+
:ACTIVE: true
|
50
|
+
:OPTIONAL_HASH:
|
51
|
+
:TWITTER_ID: ~ # your Twitter ID
|
52
|
+
|
53
|
+
# weather plugin, using google's undocumented weather API and location plugin
|
54
|
+
:WEATHER:
|
55
|
+
:ACTIVE: true
|
56
|
+
:OPTIONAL_HASH:
|
57
|
+
:WEATHER_URI: http://www.google.com/ig/api?weather= # uri to get weather from
|
58
|
+
|
59
|
+
# how often to check directories, in seconds
|
60
|
+
:DIRECTORY_MONITOR_INTERVAL: 60
|
61
|
+
|
62
|
+
# how many checks to wait for until a file is considered stable
|
63
|
+
:STABLE_INTERVALS: 5
|
64
|
+
|
65
|
+
# git details, so that you can automate git and github commits in addition to git
|
66
|
+
:GIT:
|
67
|
+
:NAME: ~ # your name
|
68
|
+
:EMAIL: ~ # your email address
|
69
|
+
:USE_GITHUB: false
|
70
|
+
:GITHUB_DATA:
|
71
|
+
:GITHUB_ID: ~ # your github ID
|
72
|
+
:GITHUB_REPOSITORY: ~ # name of the guthub repository to link to
|
73
|
+
:GITHUB_URI: git@github.com
|
@@ -0,0 +1,170 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
4
|
+
# See License.txt for licensing details.
|
5
|
+
|
6
|
+
require "rubygems"
|
7
|
+
require "directory_watcher"
|
8
|
+
|
9
|
+
class RubyFlashbake
|
10
|
+
attr_reader :configuration
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@configuration = nil
|
14
|
+
@filename = nil
|
15
|
+
@dw = []
|
16
|
+
@plugins = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_file(file)
|
20
|
+
# load the configuration file
|
21
|
+
@filename = file
|
22
|
+
begin
|
23
|
+
@configuration = YAML.load_file(file)
|
24
|
+
@configuration[:GIT_SETUP] = false
|
25
|
+
@configuration[:GITHUB_SETUP] = false
|
26
|
+
rescue SystemCallError => e
|
27
|
+
puts "Configuration file \"#{file}\" not found!"
|
28
|
+
puts "Please make sure code path loads configuration before trying to load plugins."
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_config
|
34
|
+
unless @configuration
|
35
|
+
puts "Configuration not loaded before trying to work with it"
|
36
|
+
puts "Please make sure code path loads configuration before trying to load plugins."
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def configure_git(dir)
|
42
|
+
check_config
|
43
|
+
unless @configuration[:GIT_SETUP] == true
|
44
|
+
if File.directory?("#{dir}/.git") && File.exists?("#{dir}/.git/config")
|
45
|
+
@configuration[:GIT_SETUP] = true
|
46
|
+
else
|
47
|
+
if (@configuration[:GIT][:NAME] && @configuration[:GIT][:EMAIL])
|
48
|
+
Dir.chdir("#{dir}") do
|
49
|
+
puts `git init`
|
50
|
+
puts `git config user.name "#{@configuration[:GIT][:NAME]}"`
|
51
|
+
puts `git config user.email #{@configuration[:GIT][:EMAIL]}`
|
52
|
+
File.open(".gitignore", "w") do |file|
|
53
|
+
file.puts ".DS_Store\ncoverage/\n.message.tmp\n"
|
54
|
+
end
|
55
|
+
puts "Initialized git in #{dir}"
|
56
|
+
@configuration[:GIT_SETUP] = true
|
57
|
+
end
|
58
|
+
else
|
59
|
+
puts "Can't configure git without git :NAME and :EMAIL configured in config file."
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
|
67
|
+
def configure_github(dir)
|
68
|
+
check_config
|
69
|
+
unless @configuration[:GIT_SETUP] == true
|
70
|
+
puts "Trying to configure github without previous call to config_git."
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
unless @configuration[:GITHUB_SETUP] == true
|
74
|
+
contents = File.read("#{dir}/.git/config")
|
75
|
+
if contents =~ /\[remote \"origin\"\]/
|
76
|
+
@configuration[:GITHUB_SETUP] = true
|
77
|
+
else
|
78
|
+
Dir.chdir("#{dir}") do
|
79
|
+
if !@configuration[:GITHUB_SETUP] && @configuration[:GIT][:GITHUB_DATA][:GITHUB_URI] && @configuration[:GIT][:GITHUB_DATA][:GITHUB_ID] && @configuration[:GIT][:GITHUB_DATA][:GITHUB_REPOSITORY]
|
80
|
+
puts `git remote add origin #{configuration[:GIT][:GITHUB_DATA][:GITHUB_URI]}:#{@configuration[:GIT][:GITHUB_DATA][:GITHUB_ID]}/#{@configuration[:GIT][:GITHUB_DATA][:GITHUB_REPOSITORY]}.git`
|
81
|
+
puts "Initialized github in #{dir}"
|
82
|
+
@configuration[:GITHUB_SETUP] = true
|
83
|
+
else
|
84
|
+
puts "Can't configure github without :GITHUB_URI, :GITHUB_ID, and :GITHUB_REPOSITORY configured in config file."
|
85
|
+
exit 1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
Dir.chdir("#{dir}") do
|
91
|
+
puts `git pull origin master`
|
92
|
+
end
|
93
|
+
return true
|
94
|
+
end
|
95
|
+
|
96
|
+
def git_commit(dir, message)
|
97
|
+
if @configuration[:GIT_SETUP] == true
|
98
|
+
Dir.chdir("#{dir}") do
|
99
|
+
File.open(".message.tmp", "w") {|file| file.puts message}
|
100
|
+
puts `git add .`
|
101
|
+
puts `git commit -a --file=.message.tmp`
|
102
|
+
File.delete(".message.tmp")
|
103
|
+
if @configuration[:INTERNET_ALIVE] && @configuration[:GIT][:USE_GITHUB] && @configuration[:GITHUB_SETUP]
|
104
|
+
puts `git push origin master`
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def load_plugins
|
111
|
+
check_config
|
112
|
+
|
113
|
+
@configuration[:PLUGIN_DIRECTORIES].each do |dir|
|
114
|
+
libdir = File.dirname(__FILE__)
|
115
|
+
pattern = File.join(libdir, "#{dir}", "*.rb")
|
116
|
+
Dir.glob(pattern).each do |file|
|
117
|
+
require file
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
@configuration[:PLUGIN_CALL_ORDER].each {|p| @plugins.push p }
|
122
|
+
end
|
123
|
+
|
124
|
+
def setup_directory_watchers(basedir, &block)
|
125
|
+
check_config
|
126
|
+
|
127
|
+
dw = DirectoryWatcher.new("#{basedir}")
|
128
|
+
dw.interval = @configuration[:DIRECTORY_MONITOR_INTERVAL]
|
129
|
+
dw.stable = @configuration[:STABLE_INTERVALS]
|
130
|
+
dw.glob = "**/*"
|
131
|
+
|
132
|
+
dw.add_observer do |*events|
|
133
|
+
block.call(events, basedir, checkin_comment)
|
134
|
+
end
|
135
|
+
@dw.push dw
|
136
|
+
end
|
137
|
+
|
138
|
+
def setup_watch_commits(bdir)
|
139
|
+
setup_directory_watchers(bdir) do |events, basedir, func|
|
140
|
+
events.each do |event|
|
141
|
+
if event.type == :stable
|
142
|
+
puts "#{event}" if @configuration[:VERBOSE]
|
143
|
+
git_commit("#{basedir}", func)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def start_directory_watchers
|
150
|
+
@dw.each do |dw|
|
151
|
+
dw.start
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def stop_directory_watchers
|
156
|
+
@dw.each {|dw| dw.stop}
|
157
|
+
end
|
158
|
+
|
159
|
+
def do_plugins
|
160
|
+
@plugins.each do |p|
|
161
|
+
send "do_#{p.to_s.downcase}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def checkin_comment
|
166
|
+
@configuration[:OUTPUT] = []
|
167
|
+
do_plugins
|
168
|
+
@configuration[:OUTPUT].to_yaml
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# options
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
require "optparse"
|
8
|
+
|
9
|
+
class RubyFlashbakeOptions
|
10
|
+
DEFAULT_CONFIG_FILE = ".rubyflashbake"
|
11
|
+
attr_reader :config_file
|
12
|
+
|
13
|
+
def initialize(argv)
|
14
|
+
@config_file = DEFAULT_CONFIG_FILE
|
15
|
+
parse(argv)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test(val)
|
19
|
+
[:config_file => @config_file] == val
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def parse(argv)
|
24
|
+
OptionParser.new do |opts|
|
25
|
+
opts.banner = "Usage: rubyflashbake [ options ]"
|
26
|
+
|
27
|
+
opts.on("-c [file]", "--config [file]", "Use config file [file]") do |file|
|
28
|
+
@config_file = file if file
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-e", "--example", "Dump an example, annotated config file to stdout and exit") do
|
32
|
+
example = File.read("#{File.dirname(__FILE__)}/../data/.rubyflashbake_example")
|
33
|
+
puts example
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-h", "--help", "You're looking at it. Functionality documented in config file and on first run.") do
|
38
|
+
puts opts
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
begin
|
43
|
+
opts.parse!(argv)
|
44
|
+
rescue OptionParser::ParseError => e
|
45
|
+
puts opts
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# time plug in
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
require 'ping'
|
8
|
+
|
9
|
+
class RubyFlashbake
|
10
|
+
def do_internet
|
11
|
+
@configuration[:INTERNET_ALIVE] = false
|
12
|
+
if @configuration[:PLUGIN][:INTERNET][:ACTIVE]
|
13
|
+
@configuration[:INTERNET_ALIVE] = Ping.pingecho(@configuration[:PLUGIN][:INTERNET][:OPTIONAL_HASH][:INTERNET_TEST_URI],2,80)
|
14
|
+
unless @configuration[:INTERNET_ALIVE]
|
15
|
+
@configuration[:OUTPUT].push "offline"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# time plug in
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
require 'net/http'
|
8
|
+
|
9
|
+
class RubyFlashbake
|
10
|
+
def do_location
|
11
|
+
if @configuration[:PLUGIN][:LOCATION][:ACTIVE] && @configuration[:INTERNET_ALIVE]
|
12
|
+
location = Net::HTTP.get(URI.parse("http://j.maxmind.com/app/geoip.js"))
|
13
|
+
location_array = location.scan(/return \'(.*)\'/)
|
14
|
+
@configuration[:LOCATION_CITY] = "#{location_array[2][0]}"
|
15
|
+
@configuration[:LOCATION_STATE] = "#{location_array[3][0]}"
|
16
|
+
@configuration[:LOCATION_COUNTRY] = "#{location_array[0][0]}"
|
17
|
+
if @configuration[:LOCATION_COUNTRY] == "US"
|
18
|
+
@configuration[:LOCATION_CACHE] = "#{@configuration[:LOCATION_CITY]},#{@configuration[:LOCATION_STATE]},#{@configuration[:LOCATION_COUNTRY]}"
|
19
|
+
else
|
20
|
+
@configuration[:LOCATION_CACHE] = "#{@configuration[:LOCATION_CITY]},#{@configuration[:LOCATION_COUNTRY]}"
|
21
|
+
end
|
22
|
+
@configuration[:OUTPUT].push "#{@configuration[:LOCATION_CACHE]} #{location_array[5][0]},#{location_array[6][0]}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# time plug in
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
class RubyFlashbake
|
8
|
+
def do_time
|
9
|
+
if @configuration[:PLUGIN][:TIME][:ACTIVE]
|
10
|
+
@configuration[:OUTPUT].push "#{Time.now.ctime} #{Time.now.zone}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# time plug in
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
require 'net/http'
|
8
|
+
require "hpricot"
|
9
|
+
|
10
|
+
class RubyFlashbake
|
11
|
+
def do_twitter
|
12
|
+
@configuration[:OUTPUT] = ["Couldn't reach twitter"]
|
13
|
+
if @configuration[:PLUGIN][:TIME][:ACTIVE] && @configuration[:INTERNET_ALIVE] && @configuration[:PLUGIN][:TWITTER][:OPTIONAL_HASH][:TWITTER_ID]
|
14
|
+
xml = Net::HTTP.get(URI.parse("http://twitter.com/statuses/user_timeline/#{@configuration[:PLUGIN][:TWITTER][:OPTIONAL_HASH][:TWITTER_ID]}.xml"))
|
15
|
+
doc = Hpricot(xml)
|
16
|
+
(0..2).each do |i|
|
17
|
+
if ((doc/"status"/"created_at")[i])
|
18
|
+
@configuration[:OUTPUT].push "Twitter: #{(doc/"status"/"created_at")[i].inner_html} #{(doc/"status"/"text")[i].inner_html}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# time plug in
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
require 'net/http'
|
8
|
+
class RubyFlashbake
|
9
|
+
def do_weather
|
10
|
+
@configuration[:OUTPUT].push "No valid weather found"
|
11
|
+
if @configuration[:PLUGIN][:WEATHER][:ACTIVE] && @configuration[:INTERNET_ALIVE]
|
12
|
+
if @configuration[:LOCATION_CACHE]
|
13
|
+
weather = Net::HTTP.get(URI.parse("http://www.google.com/ig/api?weather=#{@configuration[:LOCATION_CACHE]}"))
|
14
|
+
if weather =~ /temp_f data=\"(\d+)\"/ && weather =~ /condition data=\"([\s\w]+)\"/
|
15
|
+
@configuration[:OUTPUT].push "#{weather.scan(/temp_f data=\"(\d+)\"/)[0][0]} #{weather.scan(/condition data=\"([\s\w]+)\"/)[0][0]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/rspec_suite.rb
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
4
|
+
# See License.txt for licensing details.
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubyflashbake/core"
|
7
|
+
|
8
|
+
describe RubyFlashbake do
|
9
|
+
before :each do
|
10
|
+
@stdout_orig = $stdout
|
11
|
+
$stdout = StringIO.new
|
12
|
+
FileUtils.rm_rf("#{File.dirname(__FILE__)}/.git")
|
13
|
+
FileUtils.rm_rf("#{File.dirname(__FILE__)}/testdata/testdir/.git")
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
$stdout = @stdout_orig
|
18
|
+
FileUtils.rm_rf("#{File.dirname(__FILE__)}/.git")
|
19
|
+
FileUtils.rm_rf("#{File.dirname(__FILE__)}/testdata/testdir/.git")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should print error message and exit if config file isn't found" do
|
23
|
+
begin
|
24
|
+
rfb = RubyFlashbake.new
|
25
|
+
rfb.load_file("notafile")
|
26
|
+
rescue SystemExit => e
|
27
|
+
$stdout.string.should == "Configuration file \"notafile\" not found!\nPlease make sure code path loads configuration before trying to load plugins.\n"
|
28
|
+
e.status.should == 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should read in config file as YAML and return hash if file is found" do
|
33
|
+
rfb = RubyFlashbake.new
|
34
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
35
|
+
test = YAML.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
36
|
+
test[:GIT_SETUP] = false
|
37
|
+
test[:GITHUB_SETUP] = false
|
38
|
+
|
39
|
+
rfb.configuration.should == test
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should complain if git name and email address aren't filled in" do
|
43
|
+
rfb = RubyFlashbake.new
|
44
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should exit if you try to examine git config without loading config file" do
|
48
|
+
begin
|
49
|
+
rfb = RubyFlashbake.new
|
50
|
+
rfb.configure_git("#{File.dirname(__FILE__)}")
|
51
|
+
rescue SystemExit => e
|
52
|
+
$stdout.string.should == "Configuration not loaded before trying to work with it\nPlease make sure code path loads configuration before trying to load plugins.\n"
|
53
|
+
e.status.should == 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should exit with a useful error message if name and email aren't configured" do
|
58
|
+
begin
|
59
|
+
rfb = RubyFlashbake.new
|
60
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
61
|
+
rfb.configure_git("#{File.dirname(__FILE__)}").should == false
|
62
|
+
rescue SystemExit => e
|
63
|
+
$stdout.string.should == "Can't configure git without git :NAME and :EMAIL configured in config file.\n"
|
64
|
+
e.status.should == 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should configure git in watch directiory if name and email are setup and git not configured" do
|
69
|
+
rfb = RubyFlashbake.new
|
70
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
71
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
72
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
73
|
+
rfb.configure_git("#{File.dirname(__FILE__)}").should == true
|
74
|
+
$stdout.string.scan("Initialized empty Git repository").should_not == []
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be able to call configure_git multiple times once git is setup" do
|
78
|
+
begin
|
79
|
+
rfb = RubyFlashbake.new
|
80
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
81
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
82
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
83
|
+
rfb.configure_git("#{File.dirname(__FILE__)}").should == true
|
84
|
+
rfb.configure_git("#{File.dirname(__FILE__)}").should == true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should find .git and .git/config files as signal that git was setup in directory before" do
|
89
|
+
begin
|
90
|
+
rfb = RubyFlashbake.new
|
91
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
92
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
93
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
94
|
+
Dir.mkdir("#{File.dirname(__FILE__)}/.git")
|
95
|
+
File.open("#{File.dirname(__FILE__)}/.git/config", "w") {|file| file.puts "foo!"}
|
96
|
+
rfb.configure_git("#{File.dirname(__FILE__)}").should == true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should dump useful error message if uri, github id, and repository aren't setup and git not configured" do
|
101
|
+
begin
|
102
|
+
rfb = RubyFlashbake.new
|
103
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
104
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
105
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
106
|
+
rfb.configure_git("#{File.dirname(__FILE__)}")
|
107
|
+
rfb.configure_github("#{File.dirname(__FILE__)}")
|
108
|
+
rescue SystemExit => e
|
109
|
+
$stdout.string.should == "Initialized empty Git repository in /Users/cory/opensource/rubyflashbake/spec/rubyflashbake/.git/\n\n\nInitialized git in ./spec/rubyflashbake\nCan't configure github without :GITHUB_URI, :GITHUB_ID, and :GITHUB_REPOSITORY configured in config file.\n"
|
110
|
+
e.status.should == 1
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should configure github if uri, github id, and repository are setup and git not configured" do
|
115
|
+
begin
|
116
|
+
rfb = RubyFlashbake.new
|
117
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
118
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
119
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
120
|
+
rfb.configuration[:GIT][:USE_GITHUB] = true
|
121
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_ID] = "fake"
|
122
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_REPOSITORY] = "fake"
|
123
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_URI] = "git@github.com"
|
124
|
+
rfb.configure_git("#{File.dirname(__FILE__)}")
|
125
|
+
rfb.configure_github("#{File.dirname(__FILE__)}").should == true
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should fail if trying to configure github without first configuring git" do
|
130
|
+
begin
|
131
|
+
rfb = RubyFlashbake.new
|
132
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
133
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
134
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
135
|
+
rfb.configuration[:GIT][:USE_GITHUB] = true
|
136
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_ID] = "fake"
|
137
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_REPOSITORY] = "fake"
|
138
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_URI] = "git@github.com"
|
139
|
+
rfb.configure_github("#{File.dirname(__FILE__)}")
|
140
|
+
rescue SystemExit => e
|
141
|
+
$stdout.string.should == "Trying to configure github without previous call to config_git.\n"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should find .git and .git/config files as signal that git was setup in directory before" do
|
146
|
+
begin
|
147
|
+
rfb = RubyFlashbake.new
|
148
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
149
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
150
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
151
|
+
Dir.mkdir("#{File.dirname(__FILE__)}/.git")
|
152
|
+
File.open("#{File.dirname(__FILE__)}/.git/config", "w") {|file| file.puts "[remote origin]"}
|
153
|
+
rfb.configure_git("#{File.dirname(__FILE__)}").should == true
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should be fine to repated configure github" do
|
158
|
+
begin
|
159
|
+
rfb = RubyFlashbake.new
|
160
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
161
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
162
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
163
|
+
rfb.configuration[:GIT][:USE_GITHUB] = true
|
164
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_ID] = "fake"
|
165
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_REPOSITORY] = "fake"
|
166
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_URI] = "git@github.com"
|
167
|
+
rfb.configure_git("#{File.dirname(__FILE__)}")
|
168
|
+
rfb.configure_github("#{File.dirname(__FILE__)}").should == true
|
169
|
+
rfb.configure_github("#{File.dirname(__FILE__)}").should == true
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should define a plugin directory" do
|
174
|
+
rfb = RubyFlashbake.new
|
175
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
176
|
+
rfb.configuration[:PLUGIN_DIRECTORIES][0].should == "plugins"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should exit if you try to load plugins without loading config file" do
|
180
|
+
begin
|
181
|
+
rfb = RubyFlashbake.new
|
182
|
+
rfb.load_plugins
|
183
|
+
rescue SystemExit => e
|
184
|
+
$stdout.string.should == "Configuration not loaded before trying to work with it\nPlease make sure code path loads configuration before trying to load plugins.\n"
|
185
|
+
e.status.should == 1
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should load files from the specified plugins directory" do
|
190
|
+
rfb = RubyFlashbake.new
|
191
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
192
|
+
rfb.load_plugins
|
193
|
+
files = Dir.glob("#{File.dirname(__FILE__)}/../../lib/rubyflashbake/#{rfb.configuration[:PLUGIN_DIRECTORIES]}/*.rb")
|
194
|
+
files.each do |file|
|
195
|
+
basename = File.basename(file, ".rb")
|
196
|
+
RubyFlashbake.method_defined?("do_#{basename}").should == true
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should setup directory watchers as specified in the in config file" do
|
201
|
+
rfb = RubyFlashbake.new
|
202
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
203
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
204
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
205
|
+
rfb.configuration[:GIT][:USE_GITHUB] = true
|
206
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_ID] = "fake"
|
207
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_REPOSITORY] = "fake"
|
208
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_URI] = "git@github.com"
|
209
|
+
rfb.configuration[:DIRECTORY_MONITOR_INTERVAL] = 1
|
210
|
+
rfb.configuration[:STABLE_INTERVALS] = 1
|
211
|
+
rfb.configure_git("#{File.dirname(__FILE__)}/testdata/testdir/")
|
212
|
+
rfb.configure_github("#{File.dirname(__FILE__)}/testdata/testdir/")
|
213
|
+
rfb.load_plugins
|
214
|
+
output = ""
|
215
|
+
rfb.setup_directory_watchers("#{File.dirname(__FILE__)}/testdata/testdir/") do |events, basedir, func|
|
216
|
+
events.each do |event|
|
217
|
+
if event.type == :stable
|
218
|
+
output += "#{basedir} #{event}\n#{func}"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
rfb.start_directory_watchers
|
223
|
+
File.open("#{File.dirname(__FILE__)}/testdata/testdir/temp.txt", "w") {|file| file.puts "foo!"}
|
224
|
+
File.open("#{File.dirname(__FILE__)}/testdata/testdir/temp2.txt", "w") {|file| file.puts "foo!"}
|
225
|
+
sleep(10)
|
226
|
+
File.open("#{File.dirname(__FILE__)}/testdata/testdir/temp3.txt", "w") {|file| file.puts "foo!"}
|
227
|
+
File.delete("#{File.dirname(__FILE__)}/testdata/testdir/temp3.txt")
|
228
|
+
File.delete("#{File.dirname(__FILE__)}/testdata/testdir/temp2.txt")
|
229
|
+
File.delete("#{File.dirname(__FILE__)}/testdata/testdir/temp.txt")
|
230
|
+
|
231
|
+
output.scan(/temp\.txt/).should_not == []
|
232
|
+
output.scan(/temp2\.txt/).should_not == []
|
233
|
+
output.scan(/temp3\.txt/).should == []
|
234
|
+
|
235
|
+
rfb.stop_directory_watchers
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should commit changes on stable files with the commit message" do
|
239
|
+
rfb = RubyFlashbake.new
|
240
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
241
|
+
rfb.configuration[:GIT][:NAME] = "Test Monkey"
|
242
|
+
rfb.configuration[:GIT][:EMAIL] = "mokey@fake.fake"
|
243
|
+
rfb.configuration[:GIT][:USE_GITHUB] = true
|
244
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_ID] = "fake"
|
245
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_REPOSITORY] = "fake"
|
246
|
+
rfb.configuration[:GIT][:GITHUB_DATA][:GITHUB_URI] = "git@github.com"
|
247
|
+
rfb.configuration[:DIRECTORY_MONITOR_INTERVAL] = 1
|
248
|
+
rfb.configuration[:STABLE_INTERVALS] = 1
|
249
|
+
rfb.configure_git("#{File.dirname(__FILE__)}/testdata/testdir/")
|
250
|
+
rfb.configure_github("#{File.dirname(__FILE__)}/testdata/testdir/")
|
251
|
+
rfb.load_plugins
|
252
|
+
|
253
|
+
rfb.setup_watch_commits("#{File.dirname(__FILE__)}/testdata/testdir")
|
254
|
+
|
255
|
+
rfb.start_directory_watchers
|
256
|
+
File.open("#{File.dirname(__FILE__)}/testdata/testdir/temp.txt", "w") {|file| file.puts "foo!"}
|
257
|
+
File.open("#{File.dirname(__FILE__)}/testdata/testdir/temp2.txt", "w") {|file| file.puts "foo!"}
|
258
|
+
sleep(10)
|
259
|
+
File.open("#{File.dirname(__FILE__)}/testdata/testdir/temp3.txt", "w") {|file| file.puts "foo!"}
|
260
|
+
File.open("#{File.dirname(__FILE__)}/testdata/testdir/temp3.txt", "a") {|file| file.puts "bar!"}
|
261
|
+
File.delete("#{File.dirname(__FILE__)}/testdata/testdir/temp2.txt")
|
262
|
+
sleep(10)
|
263
|
+
|
264
|
+
rfb.stop_directory_watchers
|
265
|
+
|
266
|
+
status = ""
|
267
|
+
log = ""
|
268
|
+
|
269
|
+
Dir.chdir("#{File.dirname(__FILE__)}/testdata/testdir/") do
|
270
|
+
status = `git status`
|
271
|
+
log = `git log`
|
272
|
+
end
|
273
|
+
|
274
|
+
File.delete("#{File.dirname(__FILE__)}/testdata/testdir/temp3.txt")
|
275
|
+
File.delete("#{File.dirname(__FILE__)}/testdata/testdir/temp.txt")
|
276
|
+
|
277
|
+
status.should == "# On branch master\nnothing to commit (working directory clean)\n"
|
278
|
+
log.scan(/commit/).length.should == 2
|
279
|
+
end
|
280
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# options_spec
|
4
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
5
|
+
# See License.txt for licensing details.
|
6
|
+
|
7
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubyflashbake/options"
|
8
|
+
|
9
|
+
RubyFlashbakeOptionHelp = <<-EOF
|
10
|
+
Usage: rubyflashbake [ options ]
|
11
|
+
-c, --config [file] Use config file [file]
|
12
|
+
-e, --example Dump an example, annotated config file to stdout and exit
|
13
|
+
-h, --help You're looking at it. Functionality documented in config file and on first run.
|
14
|
+
EOF
|
15
|
+
|
16
|
+
describe RubyFlashbakeOptions do
|
17
|
+
before :each do
|
18
|
+
@stdout_orig = $stdout
|
19
|
+
$stdout = StringIO.new
|
20
|
+
end
|
21
|
+
|
22
|
+
after :each do
|
23
|
+
$stdout = @stdout_orig
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should default to config file .rubyflashbake, example false" do
|
27
|
+
RubyFlashbakeOptions.new([]).test([:config_file => ".rubyflashbake"]).should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should read from config file if -c given without a file" do
|
31
|
+
RubyFlashbakeOptions.new(["-c"]).test([:config_file => ".rubyflashbake"]).should == true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should read from config file if --config given without a file" do
|
35
|
+
RubyFlashbakeOptions.new(["--config"]).test([:config_file => ".rubyflashbake"]).should == true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should read from config file if -c foo option given" do
|
39
|
+
RubyFlashbakeOptions.new(["-c", "foo"]).test([:config_file => "foo"]).should == true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should read from config file if --config foo option given" do
|
43
|
+
RubyFlashbakeOptions.new(["--config", "foo"]).test([:config_file => "foo"]).should == true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should print out help when -h is requested or not input" do
|
47
|
+
begin
|
48
|
+
RubyFlashbakeOptions.new(["-h"])
|
49
|
+
rescue SystemExit => e
|
50
|
+
$stdout.string.should == RubyFlashbakeOptionHelp
|
51
|
+
e.status.should == 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should print out help when --help is requested or not input" do
|
56
|
+
begin
|
57
|
+
RubyFlashbakeOptions.new(["--help"])
|
58
|
+
rescue SystemExit => e
|
59
|
+
$stdout.string.should == RubyFlashbakeOptionHelp
|
60
|
+
e.status.should == 0
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should handle junk by dumping help and exiting" do
|
65
|
+
begin
|
66
|
+
RubyFlashbakeOptions.new(["-this is -junky junk"]).should == true
|
67
|
+
rescue SystemExit => e
|
68
|
+
$stdout.string.should == RubyFlashbakeOptionHelp
|
69
|
+
e.status.should == 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should dump example config file to stdout if -e given" do
|
74
|
+
begin
|
75
|
+
RubyFlashbakeOptions.new(["-e"])
|
76
|
+
rescue SystemExit => e
|
77
|
+
$stdout.string.should == File.read("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
78
|
+
e.status.should == 0
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should dump example config file to stdout if --example given" do
|
83
|
+
begin
|
84
|
+
RubyFlashbakeOptions.new(["--example"])
|
85
|
+
rescue SystemExit => e
|
86
|
+
$stdout.string.should == File.read("#{File.dirname(__FILE__)}/../../lib/data/.rubyflashbake_example")
|
87
|
+
e.status.should == 0
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
4
|
+
# See License.txt for licensing details.
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/core"
|
7
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/plugins/internet"
|
8
|
+
|
9
|
+
describe RubyFlashbake do
|
10
|
+
it "should set up @configuration[:INTERNET_ALIVE] to true if computer can ping the net" do
|
11
|
+
begin
|
12
|
+
rfb = RubyFlashbake.new
|
13
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
14
|
+
rfb.load_plugins
|
15
|
+
rfb.configuration[:OUTPUT] = []
|
16
|
+
rfb.do_internet
|
17
|
+
unless rfb.configuration[:OUTPUT][0] == "offline"
|
18
|
+
rfb.configuration[:INTERNET_ALIVE].should == true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set up @configuration[:INTERNET_ALIVE] to false if computer can't ping the net" do
|
24
|
+
begin
|
25
|
+
rfb = RubyFlashbake.new
|
26
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
27
|
+
rfb.load_plugins
|
28
|
+
rfb.configuration[:PLUGIN][:INTERNET][:OPTIONAL_HASH][:INTERNET_TEST_URI] = "notavalidwebaddressatall.ca"
|
29
|
+
rfb.configuration[:OUTPUT] = []
|
30
|
+
rfb.do_internet
|
31
|
+
rfb.configuration[:INTERNET_ALIVE].should == false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
4
|
+
# See License.txt for licensing details.
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/core"
|
7
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/plugins/location"
|
8
|
+
|
9
|
+
describe RubyFlashbake do
|
10
|
+
it "should pull location data from maxmind if @configuration[:INTERNET_ALIVE] is true" do
|
11
|
+
begin
|
12
|
+
rfb = RubyFlashbake.new
|
13
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
14
|
+
rfb.load_plugins
|
15
|
+
rfb.configuration[:OUTPUT] = []
|
16
|
+
rfb.do_internet
|
17
|
+
rfb.do_location
|
18
|
+
if rfb.configuration[:INTERNET_ALIVE]
|
19
|
+
rfb.configuration[:LOCATION_CACHE].scan(/(.*),(.*),(.*)/).should_not == ""
|
20
|
+
rfb.configuration[:OUTPUT][0].scan(/(.*),(.*),(.*) (.*),(.*)/).should_not == ""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should fail to get location data if @configuration[:INTERNET_ALIVE] is false" do
|
26
|
+
begin
|
27
|
+
rfb = RubyFlashbake.new
|
28
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
29
|
+
rfb.load_plugins
|
30
|
+
rfb.configuration[:PLUGIN][:INTERNET][:OPTIONAL_HASH][:INTERNET_TEST_URI] = "notavalidwebaddressatall.ca"
|
31
|
+
rfb.configuration[:OUTPUT] = []
|
32
|
+
rfb.do_internet
|
33
|
+
rfb.do_location
|
34
|
+
rfb.configuration[:LOCATION_CACHE].should == nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
4
|
+
# See License.txt for licensing details.
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/core"
|
7
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/plugins/time"
|
8
|
+
|
9
|
+
describe RubyFlashbake do
|
10
|
+
it "should pull time data" do
|
11
|
+
begin
|
12
|
+
rfb = RubyFlashbake.new
|
13
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
14
|
+
rfb.load_plugins
|
15
|
+
rfb.configuration[:OUTPUT] = []
|
16
|
+
rfb.do_time
|
17
|
+
# "Sat Apr 18 21:48:25 2009 PDT"
|
18
|
+
rfb.configuration[:OUTPUT][0].scan(/(\w*) (\w*) (\d*) (\d*):(\d*):(\d*) (\d*) (\w*)/).should_not == ""
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
4
|
+
# See License.txt for licensing details.
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/core"
|
7
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/plugins/twitter"
|
8
|
+
|
9
|
+
describe RubyFlashbake do
|
10
|
+
it "should pull last 3 tweets from twitter account if @configuration[:INTERNET_ALIVE] is true and @configuration[:PLUGIN][:TWITTER][:OPTIONAL_HASH][:TWITTER_ID] is set" do
|
11
|
+
begin
|
12
|
+
rfb = RubyFlashbake.new
|
13
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
14
|
+
rfb.load_plugins
|
15
|
+
rfb.configuration[:OUTPUT] = []
|
16
|
+
rfb.configuration[:PLUGIN][:TWITTER][:OPTIONAL_HASH][:TWITTER_ID] = "github"
|
17
|
+
rfb.do_internet
|
18
|
+
rfb.do_twitter
|
19
|
+
rfb.configuration[:OUTPUT][0].scan(/Twitter: .*/).should_not == ""
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fail to get location data if @configuration[:INTERNET_ALIVE] is false or @configuration[:PLUGIN][:TWITTER][:OPTIONAL_HASH][:TWITTER_ID] is set" do
|
24
|
+
begin
|
25
|
+
rfb = RubyFlashbake.new
|
26
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
27
|
+
rfb.load_plugins
|
28
|
+
rfb.configuration[:PLUGIN][:INTERNET][:OPTIONAL_HASH][:INTERNET_TEST_URI] = "notavalidwebaddressatall.ca"
|
29
|
+
rfb.configuration[:OUTPUT] = []
|
30
|
+
rfb.do_internet
|
31
|
+
rfb.do_twitter
|
32
|
+
rfb.configuration[:OUTPUT][0].should == "Couldn't reach twitter"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2009 Cory Ondrejka. All rights reserved.
|
4
|
+
# See License.txt for licensing details.
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/core"
|
7
|
+
require "#{File.dirname(__FILE__)}/../../../lib/rubyflashbake/plugins/weather"
|
8
|
+
|
9
|
+
describe RubyFlashbake do
|
10
|
+
it "should get weather data if @configuration[:INTERNET_ALIVE] is true" do
|
11
|
+
begin
|
12
|
+
rfb = RubyFlashbake.new
|
13
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
14
|
+
rfb.load_plugins
|
15
|
+
rfb.configuration[:OUTPUT] = []
|
16
|
+
rfb.do_internet
|
17
|
+
rfb.do_location
|
18
|
+
rfb.do_weather
|
19
|
+
if rfb.configuration[:INTERNET_ALIVE]
|
20
|
+
rfb.configuration[:LOCATION_CACHE].scan(/(.*),(.*),(.*)/).should_not == ""
|
21
|
+
rfb.configuration[:OUTPUT][0].scan(/(.*),(.*),(.*) (.*),(.*)/).should_not == ""
|
22
|
+
rfb.configuration[:OUTPUT][1].scan(/(\w+) (\w+)/).should_not == ""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fail to get weather data if @configuration[:INTERNET_ALIVE] is false" do
|
28
|
+
begin
|
29
|
+
rfb = RubyFlashbake.new
|
30
|
+
rfb.load_file("#{File.dirname(__FILE__)}/../../../lib/data/.rubyflashbake_example")
|
31
|
+
rfb.load_plugins
|
32
|
+
rfb.configuration[:PLUGIN][:INTERNET][:OPTIONAL_HASH][:INTERNET_TEST_URI] = "notavalidwebaddressatall.ca"
|
33
|
+
rfb.configuration[:OUTPUT] = []
|
34
|
+
rfb.do_internet
|
35
|
+
rfb.do_location
|
36
|
+
rfb.do_weather
|
37
|
+
rfb.configuration[:LOCATION_CACHE].should == nil
|
38
|
+
rfb.configuration[:OUTPUT][0].should == "offline"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cory-rubyflashbake
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cory Ondrejka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-08 00:00:00 -07:00
|
13
|
+
default_executable: rubyflashbake
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: cory.ondrejka@gmail.com
|
18
|
+
executables:
|
19
|
+
- rubyflashbake
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- bin/rubyflashbake
|
26
|
+
- lib/data/.rubyflashbake_example
|
27
|
+
- lib/rubyflashbake/core.rb
|
28
|
+
- lib/rubyflashbake/options.rb
|
29
|
+
- lib/rubyflashbake/plugins/internet.rb
|
30
|
+
- lib/rubyflashbake/plugins/location.rb
|
31
|
+
- lib/rubyflashbake/plugins/time.rb
|
32
|
+
- lib/rubyflashbake/plugins/twitter.rb
|
33
|
+
- lib/rubyflashbake/plugins/weather.rb
|
34
|
+
- License.txt
|
35
|
+
- README.rdoc
|
36
|
+
- README.textile
|
37
|
+
- spec/rspec_suite.rb
|
38
|
+
- spec/rubyflashbake/core_spec.rb
|
39
|
+
- spec/rubyflashbake/options_spec.rb
|
40
|
+
- spec/rubyflashbake/plugins/internet_spec.rb
|
41
|
+
- spec/rubyflashbake/plugins/location_spec.rb
|
42
|
+
- spec/rubyflashbake/plugins/time_spec.rb
|
43
|
+
- spec/rubyflashbake/plugins/twitter_spec.rb
|
44
|
+
- spec/rubyflashbake/plugins/weather_spec.rb
|
45
|
+
- spec/rubyflashbake/testdata/testdir/.gitignore
|
46
|
+
has_rdoc: false
|
47
|
+
homepage: http://cory.github.com
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "1.8"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: "A Ruby project inspired by Thomas Gideon\xE2\x80\x99s python Flashbake project"
|
72
|
+
test_files: []
|
73
|
+
|