Class: Carboy
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Carboy
- Defined in:
- lib/carboy.rb
Overview
A ruby library of standard rake tasks for building and packaging Homebrew formulae. Find information on homebrew here:
Find information on creating homebrew formulae:
The idea for creating a library of rake tasks comes from here:
More documentation on Carboy here:
- Author
-
robert tomb (mailto: [email protected])
- Copyright
-
Copyright 2012 robert tomb (bikeonastick)
- License
-
This project is licensed under the Licensed under the Apache License, Version 2.0. See LICENSE or www.apache.org/licenses/LICENSE-2.0 for a copy of the license.
Instance Attribute Summary collapse
-
#brew ⇒ Object
a way to override the Homebrew location for alternate installs.
-
#cellar ⇒ Object
readonly
if, for some reason, you need to know where the cellar is…
-
#is_package ⇒ Object
For future GIT repo support.
-
#is_repo ⇒ Object
For future GIT repo support.
-
#name ⇒ Object
the name of your project, which defaults to the name of the project directory (parent dir for the Rakefile) if not set.
-
#prod_repo ⇒ Object
For future GIT repo support.
-
#prod_site_dir ⇒ Object
Assuming you have filesystem access to your production site directory…
-
#prod_url ⇒ Object
The production url for where your homebrew package will be accessed by other users.
-
#repo_tag ⇒ Object
For future GIT repo support.
-
#test_repo ⇒ Object
For future GIT repo support.
-
#test_site_dir ⇒ Object
The local directory path to your test site, defaults to ~/Sites.
-
#test_url ⇒ Object
The url to where your test site is for installation, defaults to localhost/~<username>/.
-
#version ⇒ Object
Your project version, this is REQUIRED.
Instance Method Summary collapse
-
#copyFileReplVars(relPathFromFn, relPathToFn, submap) ⇒ Object
Copies a file from one location to another and replaces values in the file based on the contents of the map.
-
#define ⇒ Object
The predefined tasks you get by instantiating the Carboy class in your Rakefile: * hello: my first test task, it’s rather quaint, so I kept it.
-
#init(name) ⇒ Object
A vestige of an earlier idea.
-
#initialize {|_self| ... } ⇒ Carboy
constructor
Allows you to call with a block (see examples) and set values.
Constructor Details
#initialize {|_self| ... } ⇒ Carboy
Allows you to call with a block (see examples) and set values. The only required value is @version, all others are set to resonable defaults.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/carboy.rb', line 61 def initialize() @is_repo = false @is_package = true @name = nil @brew = nil @version = nil yield self if block_given? usr =`whoami`.chomp @test_site_dir = ( @test_site_dir == nil)? "/Users/#{usr}/Sites" : @test_site_dir @test_url = ( @test_url == nil)? "http://localhost/~#{usr}" : @test_url @brew = (@brew == nil)? '/usr/local' : @brew @cellar = (@cellar == nil)? "#{@brew}/Cellar" : @cellar @name = (name == nil) ? File.basename(Dir::pwd) : name @formula = @name unless @version == nil define() else raise "No version set, we can't do anything for you without it." end end |
Instance Attribute Details
#brew ⇒ Object
a way to override the Homebrew location for alternate installs
32 33 34 |
# File 'lib/carboy.rb', line 32 def brew @brew end |
#cellar ⇒ Object (readonly)
if, for some reason, you need to know where the cellar is…
55 56 57 |
# File 'lib/carboy.rb', line 55 def cellar @cellar end |
#is_package ⇒ Object
For future GIT repo support
53 54 55 |
# File 'lib/carboy.rb', line 53 def is_package @is_package end |
#is_repo ⇒ Object
For future GIT repo support
51 52 53 |
# File 'lib/carboy.rb', line 51 def is_repo @is_repo end |
#name ⇒ Object
the name of your project, which defaults to the name of the project directory (parent dir for the Rakefile) if not set
30 31 32 |
# File 'lib/carboy.rb', line 30 def name @name end |
#prod_repo ⇒ Object
For future GIT repo support
46 47 48 |
# File 'lib/carboy.rb', line 46 def prod_repo @prod_repo end |
#prod_site_dir ⇒ Object
Assuming you have filesystem access to your production site directory… DON’T USE, RESERVED FOR FUTURE USE.
42 43 44 |
# File 'lib/carboy.rb', line 42 def prod_site_dir @prod_site_dir end |
#prod_url ⇒ Object
The production url for where your homebrew package will be accessed by other users.
40 41 42 |
# File 'lib/carboy.rb', line 40 def prod_url @prod_url end |
#repo_tag ⇒ Object
For future GIT repo support
48 49 50 |
# File 'lib/carboy.rb', line 48 def repo_tag @repo_tag end |
#test_repo ⇒ Object
For future GIT repo support
44 45 46 |
# File 'lib/carboy.rb', line 44 def test_repo @test_repo end |
#test_site_dir ⇒ Object
The local directory path to your test site, defaults to ~/Sites
38 39 40 |
# File 'lib/carboy.rb', line 38 def test_site_dir @test_site_dir end |
#test_url ⇒ Object
The url to where your test site is for installation, defaults to localhost/~<username>/
36 37 38 |
# File 'lib/carboy.rb', line 36 def test_url @test_url end |
#version ⇒ Object
Your project version, this is REQUIRED. Can be a string, date, or number sequence. It will be used in filenames. Use filename-safe chars.
34 35 36 |
# File 'lib/carboy.rb', line 34 def version @version end |
Instance Method Details
#copyFileReplVars(relPathFromFn, relPathToFn, submap) ⇒ Object
Copies a file from one location to another and replaces values in the file based on the contents of the map. It just does a straight search for the key and replaces it with the value.
236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/carboy.rb', line 236 def copyFileReplVars(relPathFromFn,relPathToFn,submap) destination = File.new(relPathToFn, "w+") from = File.open(relPathFromFn) lines = from.readlines lines.each {|ln| submap.each_pair{|key,value| ln.gsub!(/#{key}/,value) } destination.puts ln } destination.close from.close end |
#define ⇒ Object
The predefined tasks you get by instantiating the Carboy class in your Rakefile:
-
hello: my first test task, it’s rather quaint, so I kept it.
-
package - delegates to assemble_formula
-
prep - creates packaging and assemply directories
-
clean - removes packaging directories
-
stagefiles - copies files for packaging and does some variable substitution
-
tarzip - tars and zips your file
-
assemble_prod_formula - inserts prod_url into formula for download, does MD5 on package, injects that into formula
-
assemble_formula - inserts test_url into formula for download, does MD5 on package, injects that into formula
-
prep_test - puts the package file into your test_site_dir, and formula into homebrew’s dir structure
-
clean_test - removes package file from test_site_dir and the formula from homebrew
-
clean_testfiles - cleans all known test files (even hidden homebrew caches)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/carboy.rb', line 114 def define desc "i say hello" task :hello do puts "hello #{@name} from #{__FILE__}" puts "where #{$0}" puts "here #{self}" puts "here #{Dir::pwd}" puts "here #{@name}" end desc "top level packaging task" task :package => [:assemble_formula] do end desc "Create packging and dist dirs" task :prep do mkdir "dist" mkdir_p "assemble/#{@formula}" end desc "Clean packaging and dist dirs" task :clean do if(File.exists?("dist")) rm_r "dist" end if(File.exists?("assemble")) rm_r "assemble" end end desc "Copies files to packaging dir and injects version" task :stagefiles => [:prep] do fn = "mydev" toSub = {"@NAME@" => @name, "@CELLAR@" => @cellar, "@VER@" => @version, "@FORMULA@" => @formula} d = "assemble/#{@formula}/#{fn}" s = "bin/#{fn}" copyFileReplVars(s,d,toSub) copy("lib/mylib.rb","assemble/#{@formula}/mylib.rb") copy("man/#{fn}.1","assemble/#{@formula}/#{fn}.1") end desc "Tars and gzips file" task :tarzip => [:stagefiles] do tf_name = "../dist/#{@formula}-#{@version}.tar" cd "assemble" `tar -cvf #{tf_name} #{@formula}` cd ".." `gzip dist/#{tf_name}` end desc "Does md5, injects into install script, and copies to dist for PRODUCTION" task :assemble_prod_formula => [:tarzip] do md5 = `md5 -q dist/#{@formula}-#{@version}.tar.gz` checksum = md5.chomp fn = "#{@formula}.rb" to = "dist/#{fn}" from = "formula/#{fn}" toSub = { "@CHECKSUM@" => checksum, "@FORMULA@" => @formula, "@VER@" => @version, "@URL@" => @prod_url } copyFileReplVars(from,to,toSub) end desc "Does md5, injects into install script, and copies to dist for TEST" task :assemble_formula => [:tarzip] do md5 = `md5 -q dist/#{@formula}-#{@version}.tar.gz` checksum = md5.chomp fn = "#{@formula}.rb" to = "dist/#{fn}" from = "formula/#{fn}" toSub = { "@CHECKSUM@" => checksum, "@FORMULA@" => @formula, "@VER@" => @version, "@URL@" => @test_url } copyFileReplVars(from,to,toSub) end desc "Prepares files for test install: copies formula to /usr/local/Library/Formula and tarball to ~/Sites" task :prep_test => [:clean, :assemble_formula] do copy("dist/#{@formula}.rb","#{@brew}/Library/Formula/#{@formula}.rb") copy("dist/#{@formula}-#{@version}.tar.gz","#{@test_site_dir}") end desc "Removes package from website, brew uninstall formula, removes formula.rb" task :clean_test do out = `brew uninstall #{@formula}` puts out Rake::Task["clean_testfiles"].invoke end desc "Removes files without brew uninstall, cuz sometimes the install goes terribly wrong." task :clean_testfiles do begin rm "#{@brew}/Library/Formula/#{@formula}.rb" rescue end begin rm "#{@test_site_dir}/#{@formula}-#{@version}.tar.gz" rescue end begin usr = `whoami`.chomp rm "/Users/#{usr}/Library/Caches/Homebrew/#{@formula}-#{@version}.tar.gz" rescue end begin rm "/Library/Caches/Homebrew/#{@formula}-#{@version}.tar.gz" rescue end end end |
#init(name) ⇒ Object
A vestige of an earlier idea. It’s a lot like your appendix.
87 88 |
# File 'lib/carboy.rb', line 87 def init(name) end |