Skip to content

Commit 842177a

Browse files
author
Ben Brinckerhoff
committed
Asked Mr. Bones to generate some files and edited them. It's starting to look like a real gem ...
1 parent 3d55302 commit 842177a

23 files changed

+1199
-77
lines changed

.bnsignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The list of files that should be ignored by Mr Bones.
2+
# Lines that start with '#' are comments.
3+
#
4+
# A .gitignore file can be used instead by setting it as the ignore
5+
# file in your Rakefile:
6+
#
7+
# PROJ.ignore_file = '.gitignore'
8+
#
9+
# For a project with a C extension, the following would be a good set of
10+
# exclude patterns (uncomment them if you want to use them):
11+
# *.[oa]
12+
# *~
13+
announcement.txt
14+
coverage
15+
doc
16+
pkg

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.ditz-config
2+
.devver/
3+

History.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
== 1.0.0 / 2009-08-18
2+
3+
* 1 major enhancement
4+
* Birthday!

README.markdown

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
construct
2+
by Ben Brinckerhoff and Avdi Grimm
3+
http://github.com/devver/construct
4+
5+
== DESCRIPTION:
6+
7+
Construct is a DSL for creating temporary files and directories during testing.
8+
9+
== SYNOPSIS:
10+
11+
FIXME (code sample of usage)
12+
13+
== REQUIREMENTS:
14+
15+
* FIXME (list of requirements)
16+
17+
== INSTALL:
18+
19+
gem install devver-construct --source http://gems.github.com
20+
21+
== LICENSE:
22+
23+
(The MIT License)
24+
25+
Copyright (c) 2009
26+
27+
Permission is hereby granted, free of charge, to any person obtaining
28+
a copy of this software and associated documentation files (the
29+
'Software'), to deal in the Software without restriction, including
30+
without limitation the rights to use, copy, modify, merge, publish,
31+
distribute, sublicense, and/or sell copies of the Software, and to
32+
permit persons to whom the Software is furnished to do so, subject to
33+
the following conditions:
34+
35+
The above copyright notice and this permission notice shall be
36+
included in all copies or substantial portions of the Software.
37+
38+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
39+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
42+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Rakefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Look in the tasks/setup.rb file for the various options that can be
2+
# configured in this Rakefile. The .rake files in the tasks directory
3+
# are where the options are used.
4+
5+
begin
6+
require 'bones'
7+
Bones.setup
8+
rescue LoadError
9+
begin
10+
load 'tasks/setup.rb'
11+
rescue LoadError
12+
raise RuntimeError, '### please install the "bones" gem ###'
13+
end
14+
end
15+
16+
ensure_in_path 'lib'
17+
require 'construct'
18+
19+
task :default => 'test'
20+
21+
PROJ.name = 'construct'
22+
23+
PROJ.authors = 'Ben Brinckerhoff ([email protected]) and Avdi Grimm ([email protected])'
24+
25+
PROJ.url = 'http://github.com/devver/construct'
26+
PROJ.version = Construct::VERSION
27+
PROJ.rubyforge.name = 'construct'
28+
PROJ.test.files = FileList['test/**/*_test.rb']
29+
PROJ.ruby_opts = []
30+
31+
# EOF

bin/construct

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env ruby
2+
3+
require File.expand_path(
4+
File.join(File.dirname(__FILE__), %w[.. lib construct]))
5+
6+
# Put your code here
7+
8+
# EOF

construct.rb

Lines changed: 0 additions & 71 deletions
This file was deleted.

lib/construct.rb

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
require 'pathname'
2+
require 'tmpdir'
3+
require 'English'
4+
5+
module Construct
6+
7+
# :stopdoc:
8+
VERSION = '1.0.0'
9+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
10+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
11+
# :startdoc:
12+
13+
# Returns the version string for the library.
14+
#
15+
def self.version
16+
VERSION
17+
end
18+
19+
# Returns the library path for the module. If any arguments are given,
20+
# they will be joined to the end of the libray path using
21+
# <tt>File.join</tt>.
22+
#
23+
def self.libpath( *args )
24+
args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
25+
end
26+
27+
# Returns the lpath for the module. If any arguments are given,
28+
# they will be joined to the end of the path using
29+
# <tt>File.join</tt>.
30+
#
31+
def self.path( *args )
32+
args.empty? ? PATH : ::File.join(PATH, args.flatten)
33+
end
34+
35+
# Utility method used to require all files ending in .rb that lie in the
36+
# directory below this file that has the same name as the filename passed
37+
# in. Optionally, a specific _directory_ name can be passed in such that
38+
# the _filename_ does not have to be equivalent to the directory.
39+
#
40+
def self.require_all_libs_relative_to( fname, dir = nil )
41+
dir ||= ::File.basename(fname, '.*')
42+
search_me = ::File.expand_path(
43+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
44+
45+
Dir.glob(search_me).sort.each {|rb| require rb}
46+
end
47+
48+
module PathExtensions
49+
50+
attr_accessor :construct__chdir_default
51+
52+
def directory(path,chdir=construct__chdir_default)
53+
subdir = (self + path)
54+
subdir.mkpath
55+
subdir.extend(PathExtensions)
56+
maybe_change_dir(chdir,subdir) do
57+
yield(subdir) if block_given?
58+
end
59+
subdir
60+
end
61+
62+
def file(filepath,contents=nil,&block)
63+
path = (self+filepath)
64+
path.dirname.mkpath
65+
File.open(path,'w') do |f|
66+
if(block)
67+
if(block.arity==1)
68+
block.call(f)
69+
else
70+
f << block.call
71+
end
72+
else
73+
f << contents
74+
end
75+
end
76+
path
77+
end
78+
79+
def maybe_change_dir(chdir,path,&block)
80+
if(chdir)
81+
Dir.chdir(path,&block)
82+
else
83+
block.call
84+
end
85+
end
86+
87+
end
88+
89+
def within_construct(chdir=true)
90+
path = (Pathname(tmpdir)+"construct_container-#{$PROCESS_ID}-#{rand(1_000_000_000)}")
91+
begin
92+
path.mkpath
93+
path.extend(PathExtensions)
94+
path.construct__chdir_default = chdir
95+
maybe_change_dir(chdir,path) do
96+
yield(path)
97+
end
98+
ensure
99+
path.rmtree
100+
end
101+
end
102+
103+
def tmpdir
104+
dir = nil
105+
Dir.chdir Dir.tmpdir do dir = Dir.pwd end # HACK FOR OSX
106+
dir
107+
end
108+
109+
extend(self)
110+
include(PathExtensions)
111+
112+
end # module Construct
113+
114+
Construct.require_all_libs_relative_to(__FILE__)
115+
116+
# EOF

tasks/ann.rake

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
begin
3+
require 'bones/smtp_tls'
4+
rescue LoadError
5+
require 'net/smtp'
6+
end
7+
require 'time'
8+
9+
namespace :ann do
10+
11+
# A prerequisites task that all other tasks depend upon
12+
task :prereqs
13+
14+
file PROJ.ann.file do
15+
ann = PROJ.ann
16+
puts "Generating #{ann.file}"
17+
File.open(ann.file,'w') do |fd|
18+
fd.puts("#{PROJ.name} version #{PROJ.version}")
19+
fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
20+
fd.puts(" #{PROJ.url}") if PROJ.url.valid?
21+
fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
22+
fd.puts
23+
fd.puts("== DESCRIPTION")
24+
fd.puts
25+
fd.puts(PROJ.description)
26+
fd.puts
27+
fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
28+
fd.puts
29+
ann.paragraphs.each do |p|
30+
fd.puts "== #{p.upcase}"
31+
fd.puts
32+
fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
33+
fd.puts
34+
end
35+
fd.puts ann.text if ann.text
36+
end
37+
end
38+
39+
desc "Create an announcement file"
40+
task :announcement => ['ann:prereqs', PROJ.ann.file]
41+
42+
desc "Send an email announcement"
43+
task :email => ['ann:prereqs', PROJ.ann.file] do
44+
ann = PROJ.ann
45+
from = ann.email[:from] || Array(PROJ.authors).first || PROJ.email
46+
to = Array(ann.email[:to])
47+
48+
### build a mail header for RFC 822
49+
rfc822msg = "From: #{from}\n"
50+
rfc822msg << "To: #{to.join(',')}\n"
51+
rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
52+
rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
53+
rfc822msg << "\n"
54+
rfc822msg << "Date: #{Time.new.rfc822}\n"
55+
rfc822msg << "Message-Id: "
56+
rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
57+
rfc822msg << File.read(ann.file)
58+
59+
params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
60+
ann.email[key]
61+
end
62+
63+
params[3] = PROJ.email if params[3].nil?
64+
65+
if params[4].nil?
66+
STDOUT.write "Please enter your e-mail password (#{params[3]}): "
67+
params[4] = STDIN.gets.chomp
68+
end
69+
70+
### send email
71+
Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
72+
end
73+
end # namespace :ann
74+
75+
desc 'Alias to ann:announcement'
76+
task :ann => 'ann:announcement'
77+
78+
CLOBBER << PROJ.ann.file
79+
80+
# EOF

0 commit comments

Comments
 (0)