Permalink
Browse files

Converted #helper calls to standard methods.

  • Loading branch information...
1 parent 3d0cdb5 commit 888915c5081c558d76f9582cd63625120b1a1ff5 @benhoskings committed Dec 21, 2010
Showing with 100 additions and 101 deletions.
  1. +15 −17 babushka.me.rb
  2. +3 −1 dns.rb
  3. +11 −13 homebrew.rb
  4. +8 −10 locale.rb
  5. +22 −24 mirroring.rb
  6. +25 −18 nginx.rb
  7. +2 −2 ruby.rb
  8. +11 −13 rvm.rb
  9. +1 −1 system.rb
  10. +2 −2 user.rb
View
@@ -1,20 +1,18 @@
meta :bab_tarball do
- template {
- helper :uri do
- 'git://github.com/benhoskings/babushka.git'
- end
- helper :latest do
- var(:tarball_path) / 'LATEST'
- end
- helper :tarball_for do |commit_id|
- var(:tarball_path) / "babushka-#{commit_id}.tgz"
- end
- helper :current_head do
- in_build_dir 'babushka' do
- `git rev-parse --short HEAD`.strip
- end
+ def uri
+ 'git://github.com/benhoskings/babushka.git'
+ end
+ def latest
+ var(:tarball_path) / 'LATEST'
+ end
+ def tarball_for commit_id
+ var(:tarball_path) / "babushka-#{commit_id}.tgz"
+ end
+ def current_head
+ in_build_dir 'babushka' do
+ `git rev-parse --short HEAD`.strip
end
- }
+ end
end
dep 'babushka tarball' do
@@ -61,10 +59,10 @@
end
dep 'babushka.me db dump' do
- helper :db_dump_path do
+ def db_dump_path
'./public/db'.p
end
- helper :db_dump do
+ def db_dump
db_dump_path / 'babushka.me.psql'
end
met? {
View
4 dns.rb
@@ -1,6 +1,8 @@
dep 'dnsmasq' do
requires 'dnsmasq.managed'
- helper(:dnsmasq_conf) { "/etc/dnsmasq.conf".p }
+ def dnsmasq_conf
+ "/etc/dnsmasq.conf".p
+ end
setup {
define_var :dhcp_network,
:type => :ip_range,
View
@@ -1,7 +1,6 @@
meta :homebrew_mirror do
- template {
- helper :urls do
- script = %Q{
+ def urls
+ script = %Q{
#!/usr/bin/env ruby
prefix = `brew --prefix`.chomp
@@ -18,25 +17,24 @@
classes_to_skip = %w[AspellLang COREUTILS_ALIASES DICT_CONF Rational SOLR_START_SCRIPT]
urls = (Class.constants - before - classes_to_skip).reject {|k|
- k =~ /DownloadStrategy$/
+k =~ /DownloadStrategy$/
}.map {|k|
- eval(k.to_s)
+eval(k.to_s)
}.select {|k|
- k.respond_to? :url
+k.respond_to? :url
}.map {|k|
- k.url
+k.url
}
puts urls * "\n"
- }
- shell("ruby", :input => script).split("\n").select {|url| url[/^(https?|ftp):/] }.uniq
- end
- }
+ }
+ shell("ruby", :input => script).split("\n").select {|url| url[/^(https?|ftp):/] }.uniq
+ end
end
dep 'mirrored.homebrew_mirror' do
define_var :homebrew_downloads, :default => '/srv/http/files'
define_var :homebrew_vhost_root, :default => '/srv/http/homebrew'
- helper :missing_urls do
+ def missing_urls
urls.tap {|urls| log "#{urls.length} URLs in the homebrew database." }.reject {|url|
path = var(:homebrew_downloads) / File.basename(url)
path.exists? && !path.empty?
@@ -58,7 +56,7 @@
dep 'linked.homebrew_mirror' do
requires 'mirrored.homebrew_mirror'
- helper :unlinked_urls do
+ def unlinked_urls
urls.tap {|urls| log "#{urls.length} URLs in the homebrew download pool." }.select {|url|
path = var(:homebrew_downloads) / File.basename(url)
link = var(:homebrew_vhost_root) / url.sub(/^[a-z]+:\/\/[^\/]+\//, '')
View
@@ -1,14 +1,12 @@
meta :locale do
- template {
- helper :locale_regex do
- /[\w]+\.utf8/
- end
- helper :local_locale do
- shell('locale -a').split("\n").detect {|l|
- l[locale_regex]
- }
- end
- }
+ def locale_regex
+ /[\w]+\.utf8/
+ end
+ def local_locale
+ shell('locale -a').split("\n").detect {|l|
+ l[locale_regex]
+ }
+ end
end
dep 'set.locale' do
View
@@ -1,21 +1,21 @@
dep 'mirror has assets' do
define_var :mirror_prefix, :default => '/srv/http' #L{ "http://#{var(:mirror_path).p.basename}" }
define_var :local_path, :default => :mirror_domain
- helper :scanned_urls do
+ def scanned_urls
(var(:mirror_prefix) / var(:local_path)).glob("**/*").select {|f|
f[/\.(html?|css)$/i]
}.map {|f|
f.p.read.scan(/url\(['"]?([^)'"]+)['"]?\)/).flatten
}.flatten.uniq
end
- helper :asset_map do
+ def asset_map
scanned_urls.group_by {|url|
url[/^(http\:)?\/\//] ? url.scan(/^[http\:]*\/\/([^\/]+)/).flatten.first : var(:mirror_domain)
}.map_values {|domain,urls|
urls.map {|url| url.sub(/^(http\:)?\/\/[^\/]+\//, '') }
}
end
- helper :nonexistent_asset_map do
+ def nonexistent_asset_map
asset_map.map_values {|domain,assets|
assets.reject {|asset|
path = var(:mirror_prefix) / domain / asset
@@ -35,22 +35,20 @@
end
meta :twitter do
- template {
- helper :users do
- "~/Desktop/rc7/campers.txt".p.read.split(/\n+/).uniq.map {|name| name.sub(/^@/, '') }
- end
- helper :avatars do
- users.map {|user|
- path = "~/Desktop/rc7/avatars/".p.glob("#{user}.*").first
- path.p unless path.nil?
- }.compact
- end
- helper :missing_avatars do
- avatars.reject {|avatar|
- avatar.exists? && !avatar.empty?
- }
- end
- }
+ def users
+ "~/Desktop/rc7/campers.txt".p.read.split(/\n+/).uniq.map {|name| name.sub(/^@/, '') }
+ end
+ def avatars
+ users.map {|user|
+ path = "~/Desktop/rc7/avatars/".p.glob("#{user}.*").first
+ path.p unless path.nil?
+ }.compact
+ end
+ def missing_avatars
+ avatars.reject {|avatar|
+ avatar.exists? && !avatar.empty?
+ }
+ end
end
dep 'avatars mirrored.twitter' do
@@ -96,10 +94,10 @@
end
dep 'gravatars mirrored' do
- helper :users do
+ def users
"~/Desktop/rc7/emails.txt".p.read.split(/\n+/).uniq
end
- helper :missing_avatars do
+ def missing_avatars
users.reject {|user| "~/Desktop/rc7/gravatars/#{user}.jpg".p.exists? }
end
met? { missing_avatars.empty? }
@@ -115,10 +113,10 @@
dep 'google ajax libs mirrored' do
define_var :mirror_root, :default => '/srv/http/ajax.googleapis.com'
- helper :search_libstate do |doc,key|
+ def search_libstate doc, key
doc.search("dd.al-libstate[text()*='#{key}:']").text.gsub("#{key}:", '').strip
end
- helper :urls do
+ def urls
require 'rubygems'
require 'hpricot'
require 'net/http'
@@ -132,7 +130,7 @@
}
}.flatten
end
- helper :missing_urls do
+ def missing_urls
urls.tap {|urls|
log "#{urls.length} items to consider."
}.reject {|url| (var(:mirror_root) / url.path).exists? }.tap {|present|
View
@@ -1,25 +1,32 @@
meta :nginx do
accepts_list_for :source
accepts_list_for :extra_source
- template {
- helper(:nginx_bin) { var(:nginx_prefix) / 'sbin/nginx' }
- helper(:nginx_conf) { var(:nginx_prefix) / 'conf/nginx.conf' }
- helper(:nginx_cert_path) { var(:nginx_prefix) / 'conf/certs' }
- helper(:nginx_conf_for) {|domain,ext| var(:nginx_prefix) / "conf/vhosts/#{domain}.#{ext}" }
- helper(:nginx_conf_link_for) {|domain| var(:nginx_prefix) / "conf/vhosts/on/#{domain}.conf" }
-
- helper(:passenger_root) { Babushka::GemHelper.gem_path_for('passenger') }
-
- helper :nginx_running? do
- shell "netstat -an | grep -E '^tcp.*[.:]80 +.*LISTEN'"
- end
-
- helper :restart_nginx do
- if nginx_running?
- log_shell "Restarting nginx", "#{nginx_bin} -s reload", :sudo => true
- end
+ def nginx_bin
+ var(:nginx_prefix) / 'sbin/nginx'
+ end
+ def nginx_conf
+ var(:nginx_prefix) / 'conf/nginx.conf'
+ end
+ def nginx_cert_path
+ var(:nginx_prefix) / 'conf/certs'
+ end
+ def nginx_conf_for domain, ext
+ var(:nginx_prefix) / "conf/vhosts/#{domain}.#{ext}"
+ end
+ def nginx_conf_link_for domain
+ var(:nginx_prefix) / "conf/vhosts/on/#{domain}.conf"
+ end
+ def passenger_root
+ Babushka::GemHelper.gem_path_for('passenger')
+ end
+ def nginx_running?
+ shell "netstat -an | grep -E '^tcp.*[.:]80 +.*LISTEN'"
+ end
+ def restart_nginx
+ if nginx_running?
+ log_shell "Restarting nginx", "#{nginx_bin} -s reload", :sudo => true
end
- }
+ end
end
dep 'vhost enabled.nginx' do
View
@@ -33,12 +33,12 @@
dep 'ruby symlinked' do
define_var :ruby_version, :choices => %w[18 19]
- helper :ruby_binaries do
+ def ruby_binaries
%w[erb gem irb rdoc ri ruby testrb rake].select {|rb|
(prefix / "#{rb}#{var(:ruby_version)}").exists?
}
end
- helper :prefix do
+ def prefix
'/usr/local/bin'
end
met? {
View
24 rvm.rb
@@ -1,9 +1,7 @@
meta :rvm do
- template {
- helper :rvm do |args|
- shell "~/.rvm/bin/rvm #{args}", :log => args['install']
- end
- }
+ def rvm args
+ shell "~/.rvm/bin/rvm #{args}", :log => args['install']
+ end
end
dep '1.9.2.rvm' do
@@ -30,21 +28,21 @@
end
meta :rvm_mirror do
+ def urls
+ shell("grep '_url=' ~/.rvm/config/db").split("\n").reject {|l|
+ l['_repo_url']
+ }.map {|l|
+ l.sub(/^.*_url=/, '')
+ }
+ end
template {
requires 'rvm'
- helper :urls do
- shell("grep '_url=' ~/.rvm/config/db").split("\n").reject {|l|
- l['_repo_url']
- }.map {|l|
- l.sub(/^.*_url=/, '')
- }
- end
}
end
dep 'mirrored.rvm_mirror' do
define_var :rvm_vhost_root, :default => '/srv/http/rvm'
- helper :missing_urls do
+ def missing_urls
urls.tap {|urls| log "#{urls.length} URLs in the rvm database." }.reject {|url|
path = var(:rvm_vhost_root) / url.sub(/^[a-z]+:\/\/[^\/]+\//, '')
path.exists? && !path.empty?
View
@@ -3,7 +3,7 @@ def ssh_conf_path file
end
dep 'hostname', :for => :linux do
- helper :hostname do
+ def hostname
shell 'hostname -f'
end
met? {
View
@@ -1,7 +1,7 @@
dep 'passwordless ssh logins' do
- helper(:ssh_dir) {
+ def ssh_dir
var(:home_dir_base) / var(:username) / '.ssh'
- }
+ end
met? {
sudo "grep '#{var(:your_ssh_public_key)}' '#{ssh_dir / 'authorized_keys'}'"
}

0 comments on commit 888915c

Please sign in to comment.