expiration-date 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +18 -0
- data/README.txt +126 -0
- data/Rakefile +25 -0
- data/lib/expiration-date.rb +143 -0
- data/spec/expiration-date_spec.rb +77 -0
- data/spec/spec_helper.rb +17 -0
- data/tasks/ann.rake +81 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +126 -0
- data/tasks/git.rake +41 -0
- data/tasks/manifest.rake +49 -0
- data/tasks/notes.rake +28 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +268 -0
- data/tasks/spec.rake +55 -0
- metadata +72 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
lib/expiration-date.rb
|
6
|
+
spec/expiration-date_spec.rb
|
7
|
+
spec/spec_helper.rb
|
8
|
+
tasks/ann.rake
|
9
|
+
tasks/bones.rake
|
10
|
+
tasks/gem.rake
|
11
|
+
tasks/git.rake
|
12
|
+
tasks/manifest.rake
|
13
|
+
tasks/notes.rake
|
14
|
+
tasks/post_load.rake
|
15
|
+
tasks/rdoc.rake
|
16
|
+
tasks/rubyforge.rake
|
17
|
+
tasks/setup.rb
|
18
|
+
tasks/spec.rake
|
data/README.txt
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
= Expiration Date
|
2
|
+
|
3
|
+
by Tim Pease
|
4
|
+
http://codeforpeople.rubyforge.org/expiration-date
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
Wandering the grocery aisle the other day I saw a package of bacon with a neon
|
9
|
+
green sticker screaming for all to hear "THIS BACON ONLY COSTS ONE DOLLAR!!!".
|
10
|
+
Screaming bacon always intrigues me, so I grabbed the nearest store manager. He
|
11
|
+
works at the coffee shop next door, but when I told him about the screaming
|
12
|
+
bacon he had to come and see for himself.
|
13
|
+
|
14
|
+
"Oh, it's a manager's special" he told me. "When products get too old the
|
15
|
+
manager will reduce the price so they sell more quickly. This allows new
|
16
|
+
products to be put on the shelves, and the store can make some money instead of
|
17
|
+
throwing out the expired products".
|
18
|
+
|
19
|
+
I stared at him blankly. He wandered back to the coffee shop and had a latte.
|
20
|
+
|
21
|
+
I continued to stand there thinking about expiring products and how Ruby could
|
22
|
+
benefit from neon green stickers and stale bacon. Eventually the grocery
|
23
|
+
store manager came by and asked me if everything was okay. I grabbed him by the
|
24
|
+
collar, pointed at the bacon and yelled "DO YOU KNOW WHAT THIS MEANS!?!?". I
|
25
|
+
ran from the store, grabbed my laptop, and whipped up this little gem.
|
26
|
+
|
27
|
+
EXPIRATION DATE (now with more neon green).
|
28
|
+
|
29
|
+
Now ruby can expire it's bacon, too, just like the grocery store, and make room
|
30
|
+
for more bacon from the delivery truck.
|
31
|
+
|
32
|
+
== SYNOPSIS:
|
33
|
+
|
34
|
+
The ExpirationDate module adds the "expiring_attr" method to a class. This
|
35
|
+
method is used to define an attribute that will expire after some period of
|
36
|
+
seconds have elapsed.
|
37
|
+
|
38
|
+
A simple example demonstrating how the block gets called after the expiration
|
39
|
+
time is passed.
|
40
|
+
|
41
|
+
class A
|
42
|
+
include ExpirationDate
|
43
|
+
expiring_attr( :foo, 60 ) { 'foo' }
|
44
|
+
end
|
45
|
+
|
46
|
+
a = A.new
|
47
|
+
a.foo #=> 'foo'
|
48
|
+
a.foo.object_id #=> 123456
|
49
|
+
a.foo.object_id #=> 123456
|
50
|
+
|
51
|
+
sleep 61
|
52
|
+
a.foo.object_id #=> 654321
|
53
|
+
|
54
|
+
a.foo = 'bar'
|
55
|
+
a.foo #=> 'bar'
|
56
|
+
sleep 61
|
57
|
+
a.foo #=> 'foo'
|
58
|
+
|
59
|
+
A slightly more useful example. Here we are going to extract information from a
|
60
|
+
database every five minutes. This assumes you have the 'activesupport' and
|
61
|
+
'activerecord' gems installed.
|
62
|
+
|
63
|
+
class MyModel < ::ActiveRecord::Base
|
64
|
+
include ExpirationDate
|
65
|
+
expiring_attr( :costly_data, 5.minutes ) {
|
66
|
+
models = MyModel.find( :all, :conditions => ['costly query conditions'] )
|
67
|
+
result = models.map {|m| # costly operations here}
|
68
|
+
result
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
Attributes can be expired manually, and the time it takes them to expire can be
|
73
|
+
modified as well.
|
74
|
+
|
75
|
+
class AgeDemo
|
76
|
+
include ExpirationDate
|
77
|
+
expiring_attr( :bar, 120 ) { Time.now }
|
78
|
+
end
|
79
|
+
|
80
|
+
demo = AgeDemo.new
|
81
|
+
demo.bar #=> now
|
82
|
+
|
83
|
+
sleep 60
|
84
|
+
demo.bar #=> 60 seconds ago
|
85
|
+
|
86
|
+
demo.expire_now(:bar)
|
87
|
+
demo.bar #=> now
|
88
|
+
|
89
|
+
demo.alter_expiration_label(:bar, 10)
|
90
|
+
demo.expire_now(:bar)
|
91
|
+
demo.bar #=> now
|
92
|
+
sleep 11
|
93
|
+
demo.bar #=> now
|
94
|
+
|
95
|
+
== REQUIREMENTS:
|
96
|
+
|
97
|
+
This is a pure ruby library. There are no requirements for using this code.
|
98
|
+
|
99
|
+
== INSTALL:
|
100
|
+
|
101
|
+
sudo gem install expiration-date
|
102
|
+
|
103
|
+
== LICENSE:
|
104
|
+
|
105
|
+
The MIT License
|
106
|
+
|
107
|
+
Copyright (c) 2008
|
108
|
+
|
109
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
110
|
+
a copy of this software and associated documentation files (the
|
111
|
+
'Software'), to deal in the Software without restriction, including
|
112
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
113
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
114
|
+
permit persons to whom the Software is furnished to do so, subject to
|
115
|
+
the following conditions:
|
116
|
+
|
117
|
+
The above copyright notice and this permission notice shall be
|
118
|
+
included in all copies or substantial portions of the Software.
|
119
|
+
|
120
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
121
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
122
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
123
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
124
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
125
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
126
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
load 'tasks/setup.rb'
|
3
|
+
|
4
|
+
ensure_in_path 'lib'
|
5
|
+
require 'expiration-date'
|
6
|
+
|
7
|
+
task :default => 'spec:specdoc'
|
8
|
+
|
9
|
+
PROJ.name = 'expiration-date'
|
10
|
+
PROJ.summary = 'auto-expiring / auto-refreshing attributes for your ruby classes'
|
11
|
+
PROJ.authors = 'Tim Pease'
|
12
|
+
PROJ.email = 'tim.pease@gmail.com'
|
13
|
+
PROJ.url = 'http://codeforpeople.rubyforge.org/expiration-date'
|
14
|
+
PROJ.rubyforge.name = 'codeforpeople'
|
15
|
+
PROJ.rdoc.remote_dir = 'expiration-date'
|
16
|
+
PROJ.version = ExpirationDate::VERSION
|
17
|
+
PROJ.release_name = 'Stale Green Bacon'
|
18
|
+
|
19
|
+
PROJ.spec.opts << '--color'
|
20
|
+
|
21
|
+
PROJ.ann.email[:server] = 'smtp.gmail.com'
|
22
|
+
PROJ.ann.email[:port] = 587
|
23
|
+
PROJ.ann.paragraphs << 'synopsis'
|
24
|
+
|
25
|
+
# EOF
|
@@ -0,0 +1,143 @@
|
|
1
|
+
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
module ExpirationDate
|
5
|
+
|
6
|
+
# :stopdoc:
|
7
|
+
VERSION = '1.0.0'
|
8
|
+
ExpirationLabel = Struct.new(:mutex, :age, :expires_on)
|
9
|
+
# :startdoc:
|
10
|
+
|
11
|
+
# Returns the version string for the library.
|
12
|
+
#
|
13
|
+
def self.version
|
14
|
+
VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
# This method is called whenever this module is included by another
|
18
|
+
# module. It is used to add class methods to the other module.
|
19
|
+
#
|
20
|
+
def self.included( other )
|
21
|
+
other.extend ClassMethods
|
22
|
+
end
|
23
|
+
|
24
|
+
# Container for the class methods to add to including modules.
|
25
|
+
#
|
26
|
+
module ClassMethods
|
27
|
+
|
28
|
+
# Declares a new instance attribute that will expire after _age_ seconds
|
29
|
+
# and be replaced by the results of running the _block_. The block is
|
30
|
+
# lazily evaluated when the attribute is accessed after the expiration
|
31
|
+
# time.
|
32
|
+
#
|
33
|
+
# Obviously this scheme will only work if the attribute is only accessed
|
34
|
+
# using the setter and getter methods defined by this function.
|
35
|
+
#
|
36
|
+
# class A
|
37
|
+
# include ExpirationDate
|
38
|
+
# expiring_attr( :foo, 60 ) { 'foo' }
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# a = A.new
|
42
|
+
# a.foo.object_id #=> 123456
|
43
|
+
# sleep 61
|
44
|
+
# a.foo.object_id #=> 654321
|
45
|
+
#
|
46
|
+
def expiring_attr( name, age, &block )
|
47
|
+
raise ArgumentError, "a block must be given" if block.nil?
|
48
|
+
|
49
|
+
name = name.to_sym
|
50
|
+
age = Float(age)
|
51
|
+
_managers_specials[name] = block
|
52
|
+
|
53
|
+
self.class_eval <<-CODE, __FILE__, __LINE__
|
54
|
+
def #{name}
|
55
|
+
now = Time.now
|
56
|
+
label = expiration_labels[#{name.inspect}]
|
57
|
+
if label.expires_on.nil? || now >= label.expires_on
|
58
|
+
label.mutex.synchronize {
|
59
|
+
break unless label.expires_on.nil? || now >= label.expires_on
|
60
|
+
@#{name} = ::#{self.name}._managers_specials[#{name.inspect}].call
|
61
|
+
label.age ||= #{age}
|
62
|
+
label.expires_on = now + label.age
|
63
|
+
}
|
64
|
+
end
|
65
|
+
@#{name}
|
66
|
+
end
|
67
|
+
|
68
|
+
def #{name}=( val )
|
69
|
+
now = Time.now
|
70
|
+
label = expiration_labels[#{name.inspect}]
|
71
|
+
label.mutex.synchronize {
|
72
|
+
@#{name} = val
|
73
|
+
label.age ||= #{age}
|
74
|
+
label.expires_on = now + label.age
|
75
|
+
}
|
76
|
+
@#{name}
|
77
|
+
end
|
78
|
+
CODE
|
79
|
+
end
|
80
|
+
|
81
|
+
# :stopdoc:
|
82
|
+
# Class-level hash used to hold the initialization blocks for the
|
83
|
+
# expiring attributes.
|
84
|
+
#
|
85
|
+
def _managers_specials
|
86
|
+
@_managers_specials ||= Hash.new
|
87
|
+
end
|
88
|
+
# :startdoc:
|
89
|
+
end
|
90
|
+
|
91
|
+
# Immediately expire an attribute so that it will be refreshed the next
|
92
|
+
# time it is requested.
|
93
|
+
#
|
94
|
+
# expire_now( :foo )
|
95
|
+
#
|
96
|
+
def expire_now( name )
|
97
|
+
name = name.to_sym
|
98
|
+
if expiration_labels.key?(name)
|
99
|
+
now = Time.now
|
100
|
+
label = expiration_labels[name]
|
101
|
+
label.mutex.synchronize {
|
102
|
+
label.expires_on = now - 1
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Alter the _age_ of the named attribute. This new age will be used the
|
108
|
+
# next time the attribute expries to determine the new expiration date --
|
109
|
+
# i.e. the new age does not immediately take effect. You will need to
|
110
|
+
# manually expire the attribute if you want the new age to take effect
|
111
|
+
# immediately.
|
112
|
+
#
|
113
|
+
# Modify the 'foo' attribute so that it expires every 60 seconds.
|
114
|
+
#
|
115
|
+
# alter_expiration_label( :foo, 60 )
|
116
|
+
#
|
117
|
+
# Modify the 'bar' attribute so that it expires every two minutes. Make
|
118
|
+
# this new age take effect immediately.
|
119
|
+
#
|
120
|
+
# alter_expiration_label( :bar, 120 )
|
121
|
+
# expire_now( :bar )
|
122
|
+
#
|
123
|
+
def alter_expiration_label( name, age )
|
124
|
+
name = name.to_sym
|
125
|
+
if expiration_labels.key?(name)
|
126
|
+
label = expiration_labels[name]
|
127
|
+
label.mutex.synchronize {
|
128
|
+
label.age = Float(age)
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Accessor that returns the hash of ExpirationLabel objects.
|
134
|
+
#
|
135
|
+
def expiration_labels
|
136
|
+
@expiration_labels ||= Hash.new do |h,k|
|
137
|
+
h[k] = ExpirationLabel.new(Mutex.new)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end # module ExpirationDate
|
142
|
+
|
143
|
+
# EOF
|
@@ -0,0 +1,77 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
|
4
|
+
class TestA
|
5
|
+
include ExpirationDate
|
6
|
+
|
7
|
+
expiring_attr(:foo, 0.5) { 'foo' }
|
8
|
+
expiring_attr('bar', 10 ) { 'bar' }
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
describe ExpirationDate do
|
13
|
+
it 'returns the same attribute before the expiration time' do
|
14
|
+
a = TestA.new
|
15
|
+
foo = a.foo
|
16
|
+
foo.should be_equal(a.foo)
|
17
|
+
foo.should == 'foo'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns a new attribute after the expiration time' do
|
21
|
+
a = TestA.new
|
22
|
+
foo = a.foo
|
23
|
+
foo.should be_equal(a.foo)
|
24
|
+
foo.should == 'foo'
|
25
|
+
|
26
|
+
sleep 0.75
|
27
|
+
foo.should_not be_equal(a.foo)
|
28
|
+
a.foo.should == 'foo'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can immediately expire an attribute' do
|
32
|
+
a = TestA.new
|
33
|
+
bar = a.bar
|
34
|
+
bar.should be_equal(a.bar)
|
35
|
+
bar.should == 'bar'
|
36
|
+
|
37
|
+
a.expire_now(:bar)
|
38
|
+
bar.should_not be_equal(a.bar)
|
39
|
+
a.bar.should == 'bar'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can alter an expiration label' do
|
43
|
+
a = TestA.new
|
44
|
+
bar = a.bar
|
45
|
+
bar.should be_equal(a.bar)
|
46
|
+
bar.should == 'bar'
|
47
|
+
|
48
|
+
# this alteration takes place only after the attribute expires
|
49
|
+
a.alter_expiration_label('bar', 0.5)
|
50
|
+
|
51
|
+
sleep 0.75
|
52
|
+
bar.should be_equal(a.bar)
|
53
|
+
|
54
|
+
# so now the age should only be 0.5 seconds
|
55
|
+
a.expire_now(:bar)
|
56
|
+
bar.should_not be_equal(a.bar)
|
57
|
+
a.bar.should == 'bar'
|
58
|
+
|
59
|
+
sleep 0.75
|
60
|
+
bar.should_not be_equal(a.bar)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'ignores requests on unknown expriation lables' do
|
64
|
+
a = TestA.new
|
65
|
+
|
66
|
+
h = a.expiration_labels
|
67
|
+
h.keys.length == 2
|
68
|
+
|
69
|
+
a.expire_now(:foobar)
|
70
|
+
h.keys.length == 2
|
71
|
+
|
72
|
+
a.alter_expiration_label(:foobar, 42)
|
73
|
+
h.keys.length == 2
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# EOF
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require File.expand_path(
|
4
|
+
File.join(File.dirname(__FILE__), %w[.. lib expiration-date]))
|
5
|
+
|
6
|
+
Spec::Runner.configure do |config|
|
7
|
+
# == Mock Framework
|
8
|
+
#
|
9
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
10
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
11
|
+
#
|
12
|
+
# config.mock_with :mocha
|
13
|
+
# config.mock_with :flexmock
|
14
|
+
# config.mock_with :rr
|
15
|
+
end
|
16
|
+
|
17
|
+
# EOF
|
data/tasks/ann.rake
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bones/smtp_tls'
|
5
|
+
rescue LoadError
|
6
|
+
require 'net/smtp'
|
7
|
+
end
|
8
|
+
require 'time'
|
9
|
+
|
10
|
+
namespace :ann do
|
11
|
+
|
12
|
+
# A prerequisites task that all other tasks depend upon
|
13
|
+
task :prereqs
|
14
|
+
|
15
|
+
file PROJ.ann.file do
|
16
|
+
ann = PROJ.ann
|
17
|
+
puts "Generating #{ann.file}"
|
18
|
+
File.open(ann.file,'w') do |fd|
|
19
|
+
fd.puts("#{PROJ.name} version #{PROJ.version}")
|
20
|
+
fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
|
21
|
+
fd.puts(" #{PROJ.url}") if PROJ.url.valid?
|
22
|
+
fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
|
23
|
+
fd.puts
|
24
|
+
fd.puts("== DESCRIPTION")
|
25
|
+
fd.puts
|
26
|
+
fd.puts(PROJ.description)
|
27
|
+
fd.puts
|
28
|
+
fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
|
29
|
+
fd.puts
|
30
|
+
ann.paragraphs.each do |p|
|
31
|
+
fd.puts "== #{p.upcase}"
|
32
|
+
fd.puts
|
33
|
+
fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
|
34
|
+
fd.puts
|
35
|
+
end
|
36
|
+
fd.puts ann.text if ann.text
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Create an announcement file"
|
41
|
+
task :announcement => ['ann:prereqs', PROJ.ann.file]
|
42
|
+
|
43
|
+
desc "Send an email announcement"
|
44
|
+
task :email => ['ann:prereqs', PROJ.ann.file] do
|
45
|
+
ann = PROJ.ann
|
46
|
+
from = ann.email[:from] || PROJ.email
|
47
|
+
to = Array(ann.email[:to])
|
48
|
+
|
49
|
+
### build a mail header for RFC 822
|
50
|
+
rfc822msg = "From: #{from}\n"
|
51
|
+
rfc822msg << "To: #{to.join(',')}\n"
|
52
|
+
rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
|
53
|
+
rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
|
54
|
+
rfc822msg << "\n"
|
55
|
+
rfc822msg << "Date: #{Time.new.rfc822}\n"
|
56
|
+
rfc822msg << "Message-Id: "
|
57
|
+
rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
|
58
|
+
rfc822msg << File.read(ann.file)
|
59
|
+
|
60
|
+
params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
|
61
|
+
ann.email[key]
|
62
|
+
end
|
63
|
+
|
64
|
+
params[3] = PROJ.email if params[3].nil?
|
65
|
+
|
66
|
+
if params[4].nil?
|
67
|
+
STDOUT.write "Please enter your e-mail password (#{params[3]}): "
|
68
|
+
params[4] = STDIN.gets.chomp
|
69
|
+
end
|
70
|
+
|
71
|
+
### send email
|
72
|
+
Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
|
73
|
+
end
|
74
|
+
end # namespace :ann
|
75
|
+
|
76
|
+
desc 'Alias to ann:announcement'
|
77
|
+
task :ann => 'ann:announcement'
|
78
|
+
|
79
|
+
CLOBBER << PROJ.ann.file
|
80
|
+
|
81
|
+
# EOF
|
data/tasks/bones.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_BONES
|
4
|
+
|
5
|
+
namespace :bones do
|
6
|
+
|
7
|
+
desc 'Show the PROJ open struct'
|
8
|
+
task :debug do |t|
|
9
|
+
atr = if t.application.top_level_tasks.length == 2
|
10
|
+
t.application.top_level_tasks.pop
|
11
|
+
end
|
12
|
+
|
13
|
+
if atr then Bones::Debug.show_attr(PROJ, atr)
|
14
|
+
else Bones::Debug.show PROJ end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # namespace :bones
|
18
|
+
|
19
|
+
end # HAVE_BONES
|
20
|
+
|
21
|
+
# EOF
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
namespace :gem do
|
6
|
+
|
7
|
+
PROJ.gem._spec = Gem::Specification.new do |s|
|
8
|
+
s.name = PROJ.name
|
9
|
+
s.version = PROJ.version
|
10
|
+
s.summary = PROJ.summary
|
11
|
+
s.authors = Array(PROJ.authors)
|
12
|
+
s.email = PROJ.email
|
13
|
+
s.homepage = Array(PROJ.url).first
|
14
|
+
s.rubyforge_project = PROJ.rubyforge.name
|
15
|
+
|
16
|
+
s.description = PROJ.description
|
17
|
+
|
18
|
+
PROJ.gem.dependencies.each do |dep|
|
19
|
+
s.add_dependency(*dep)
|
20
|
+
end
|
21
|
+
|
22
|
+
s.files = PROJ.gem.files
|
23
|
+
s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
|
24
|
+
s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
|
25
|
+
|
26
|
+
s.bindir = 'bin'
|
27
|
+
dirs = Dir["{#{PROJ.libs.join(',')}}"]
|
28
|
+
s.require_paths = dirs unless dirs.empty?
|
29
|
+
|
30
|
+
incl = Regexp.new(PROJ.rdoc.include.join('|'))
|
31
|
+
excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
|
32
|
+
excl = Regexp.new(excl.join('|'))
|
33
|
+
rdoc_files = PROJ.gem.files.find_all do |fn|
|
34
|
+
case fn
|
35
|
+
when excl; false
|
36
|
+
when incl; true
|
37
|
+
else false end
|
38
|
+
end
|
39
|
+
s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
|
40
|
+
s.extra_rdoc_files = rdoc_files
|
41
|
+
s.has_rdoc = true
|
42
|
+
|
43
|
+
if test ?f, PROJ.test.file
|
44
|
+
s.test_file = PROJ.test.file
|
45
|
+
else
|
46
|
+
s.test_files = PROJ.test.files.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
# Do any extra stuff the user wants
|
50
|
+
PROJ.gem.extras.each do |msg, val|
|
51
|
+
case val
|
52
|
+
when Proc
|
53
|
+
val.call(s.send(msg))
|
54
|
+
else
|
55
|
+
s.send "#{msg}=", val
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end # Gem::Specification.new
|
59
|
+
|
60
|
+
# A prerequisites task that all other tasks depend upon
|
61
|
+
task :prereqs
|
62
|
+
|
63
|
+
desc 'Show information about the gem'
|
64
|
+
task :debug => 'gem:prereqs' do
|
65
|
+
puts PROJ.gem._spec.to_ruby
|
66
|
+
end
|
67
|
+
|
68
|
+
pkg = Rake::PackageTask.new(PROJ.name, PROJ.version) do |pkg|
|
69
|
+
pkg.need_tar = PROJ.gem.need_tar
|
70
|
+
pkg.need_zip = PROJ.gem.need_zip
|
71
|
+
pkg.package_files += PROJ.gem._spec.files
|
72
|
+
end
|
73
|
+
Rake::Task['gem:package'].instance_variable_set(:@full_comment, nil)
|
74
|
+
|
75
|
+
gem_file = if PROJ.gem._spec.platform == Gem::Platform::RUBY
|
76
|
+
"#{pkg.package_name}.gem"
|
77
|
+
else
|
78
|
+
"#{pkg.package_name}-#{PROJ.gem._spec.platform}.gem"
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "Build the gem file #{gem_file}"
|
82
|
+
task :package => ['gem:prereqs', "#{pkg.package_dir}/#{gem_file}"]
|
83
|
+
|
84
|
+
file "#{pkg.package_dir}/#{gem_file}" => [pkg.package_dir] + PROJ.gem._spec.files do
|
85
|
+
when_writing("Creating GEM") {
|
86
|
+
Gem::Builder.new(PROJ.gem._spec).build
|
87
|
+
verbose(true) {
|
88
|
+
mv gem_file, "#{pkg.package_dir}/#{gem_file}"
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
desc 'Install the gem'
|
94
|
+
task :install => [:clobber, 'gem:package'] do
|
95
|
+
sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
|
96
|
+
|
97
|
+
# use this version of the command for rubygems > 1.0.0
|
98
|
+
#sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
|
99
|
+
end
|
100
|
+
|
101
|
+
desc 'Uninstall the gem'
|
102
|
+
task :uninstall do
|
103
|
+
installed_list = Gem.source_index.find_name(PROJ.name)
|
104
|
+
if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
|
105
|
+
sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
desc 'Reinstall the gem'
|
110
|
+
task :reinstall => [:uninstall, :install]
|
111
|
+
|
112
|
+
desc 'Cleanup the gem'
|
113
|
+
task :cleanup do
|
114
|
+
sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
|
115
|
+
end
|
116
|
+
|
117
|
+
end # namespace :gem
|
118
|
+
|
119
|
+
desc 'Alias to gem:package'
|
120
|
+
task :gem => 'gem:package'
|
121
|
+
|
122
|
+
task :clobber => 'gem:clobber_package'
|
123
|
+
|
124
|
+
remove_desc_for_task %w(gem:clobber_package)
|
125
|
+
|
126
|
+
# EOF
|
data/tasks/git.rake
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_GIT
|
4
|
+
|
5
|
+
namespace :git do
|
6
|
+
|
7
|
+
# A prerequisites task that all other tasks depend upon
|
8
|
+
task :prereqs
|
9
|
+
|
10
|
+
desc 'Show tags from the Git repository'
|
11
|
+
task :show_tags => 'git:prereqs' do |t|
|
12
|
+
puts %x/git tag/
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Create a new tag in the Git repository'
|
16
|
+
task :create_tag => 'git:prereqs' do |t|
|
17
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
18
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
19
|
+
|
20
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
21
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
22
|
+
|
23
|
+
puts "Creating Git tag '#{tag}'"
|
24
|
+
unless system "git tag -a -m '#{msg}' #{tag}"
|
25
|
+
abort "Tag creation failed"
|
26
|
+
end
|
27
|
+
|
28
|
+
if %x/git remote/ =~ %r/^origin\s*$/
|
29
|
+
unless system "git push origin #{tag}"
|
30
|
+
abort "Could not push tag to remote Git repository"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end # namespace :git
|
36
|
+
|
37
|
+
task 'gem:release' => 'git:create_tag'
|
38
|
+
|
39
|
+
end # if HAVE_GIT
|
40
|
+
|
41
|
+
# EOF
|
data/tasks/manifest.rake
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
|
5
|
+
namespace :manifest do
|
6
|
+
|
7
|
+
desc 'Verify the manifest'
|
8
|
+
task :check do
|
9
|
+
fn = PROJ.manifest_file + '.tmp'
|
10
|
+
files = manifest_files
|
11
|
+
|
12
|
+
File.open(fn, 'w') {|fp| fp.puts files}
|
13
|
+
lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
|
14
|
+
if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
|
15
|
+
lines.map! do |line|
|
16
|
+
case line
|
17
|
+
when %r/^(-{3}|\+{3})/; nil
|
18
|
+
when %r/^@/; Console::ANSICode.blue line
|
19
|
+
when %r/^\+/; Console::ANSICode.green line
|
20
|
+
when %r/^\-/; Console::ANSICode.red line
|
21
|
+
else line end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
puts lines.compact
|
25
|
+
rm fn rescue nil
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Create a new manifest'
|
29
|
+
task :create do
|
30
|
+
files = manifest_files
|
31
|
+
unless test(?f, PROJ.manifest_file)
|
32
|
+
files << PROJ.manifest_file
|
33
|
+
files.sort!
|
34
|
+
end
|
35
|
+
File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
|
36
|
+
end
|
37
|
+
|
38
|
+
task :assert do
|
39
|
+
files = manifest_files
|
40
|
+
manifest = File.read(PROJ.manifest_file).split($/)
|
41
|
+
raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
|
42
|
+
end
|
43
|
+
|
44
|
+
end # namespace :manifest
|
45
|
+
|
46
|
+
desc 'Alias to manifest:check'
|
47
|
+
task :manifest => 'manifest:check'
|
48
|
+
|
49
|
+
# EOF
|
data/tasks/notes.rake
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_BONES
|
4
|
+
|
5
|
+
desc "Enumerate all annotations"
|
6
|
+
task :notes do |t|
|
7
|
+
id = if t.application.top_level_tasks.length > 1
|
8
|
+
t.application.top_level_tasks.slice!(1..-1).join(' ')
|
9
|
+
end
|
10
|
+
Bones::AnnotationExtractor.enumerate(
|
11
|
+
PROJ, PROJ.notes.tags.join('|'), id, :tag => true)
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :notes do
|
15
|
+
PROJ.notes.tags.each do |tag|
|
16
|
+
desc "Enumerate all #{tag} annotations"
|
17
|
+
task tag.downcase.to_sym do |t|
|
18
|
+
id = if t.application.top_level_tasks.length > 1
|
19
|
+
t.application.top_level_tasks.slice!(1..-1).join(' ')
|
20
|
+
end
|
21
|
+
Bones::AnnotationExtractor.enumerate(PROJ, tag, id)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end # if HAVE_BONES
|
27
|
+
|
28
|
+
# EOF
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
# This file does not define any rake tasks. It is used to load some project
|
4
|
+
# settings if they are not defined by the user.
|
5
|
+
|
6
|
+
PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
|
7
|
+
PROJ.exclude << ["^#{Regexp.escape(PROJ.ann.file)}$",
|
8
|
+
"^#{Regexp.escape(PROJ.rdoc.dir)}/",
|
9
|
+
"^#{Regexp.escape(PROJ.rcov.dir)}/"]
|
10
|
+
|
11
|
+
flatten_arrays = lambda do |this,os|
|
12
|
+
os.instance_variable_get(:@table).each do |key,val|
|
13
|
+
next if key == :dependencies
|
14
|
+
case val
|
15
|
+
when Array; val.flatten!
|
16
|
+
when OpenStruct; this.call(this,val)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
flatten_arrays.call(flatten_arrays,PROJ)
|
21
|
+
|
22
|
+
PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
|
23
|
+
|
24
|
+
PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
|
25
|
+
|
26
|
+
PROJ.summary ||= PROJ.description.split('.').first
|
27
|
+
|
28
|
+
PROJ.gem.files ||=
|
29
|
+
if test(?f, PROJ.manifest_file)
|
30
|
+
files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
|
31
|
+
files.delete ''
|
32
|
+
files
|
33
|
+
else [] end
|
34
|
+
|
35
|
+
PROJ.gem.executables ||= PROJ.gem.files.find_all {|fn| fn =~ %r/^bin/}
|
36
|
+
|
37
|
+
PROJ.rdoc.main ||= PROJ.readme_file
|
38
|
+
|
39
|
+
# EOF
|
data/tasks/rdoc.rake
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
namespace :doc do
|
6
|
+
|
7
|
+
desc 'Generate RDoc documentation'
|
8
|
+
Rake::RDocTask.new do |rd|
|
9
|
+
rdoc = PROJ.rdoc
|
10
|
+
rd.main = rdoc.main
|
11
|
+
rd.rdoc_dir = rdoc.dir
|
12
|
+
|
13
|
+
incl = Regexp.new(rdoc.include.join('|'))
|
14
|
+
excl = Regexp.new(rdoc.exclude.join('|'))
|
15
|
+
files = PROJ.gem.files.find_all do |fn|
|
16
|
+
case fn
|
17
|
+
when excl; false
|
18
|
+
when incl; true
|
19
|
+
else false end
|
20
|
+
end
|
21
|
+
rd.rdoc_files.push(*files)
|
22
|
+
|
23
|
+
title = "#{PROJ.name}-#{PROJ.version} Documentation"
|
24
|
+
|
25
|
+
rf_name = PROJ.rubyforge.name
|
26
|
+
title = "#{rf_name}'s " + title if rf_name.valid? and rf_name != title
|
27
|
+
|
28
|
+
rd.options << "-t #{title}"
|
29
|
+
rd.options.concat(rdoc.opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Generate ri locally for testing'
|
33
|
+
task :ri => :clobber_ri do
|
34
|
+
sh "#{RDOC} --ri -o ri ."
|
35
|
+
end
|
36
|
+
|
37
|
+
task :clobber_ri do
|
38
|
+
rm_r 'ri' rescue nil
|
39
|
+
end
|
40
|
+
|
41
|
+
end # namespace :doc
|
42
|
+
|
43
|
+
desc 'Alias to doc:rdoc'
|
44
|
+
task :doc => 'doc:rdoc'
|
45
|
+
|
46
|
+
desc 'Remove all build products'
|
47
|
+
task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
|
48
|
+
|
49
|
+
remove_desc_for_task %w(doc:clobber_rdoc)
|
50
|
+
|
51
|
+
# EOF
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
if PROJ.rubyforge.name.valid? && HAVE_RUBYFORGE
|
3
|
+
|
4
|
+
require 'rubyforge'
|
5
|
+
require 'rake/contrib/sshpublisher'
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
desc 'Package and upload to RubyForge'
|
9
|
+
task :release => [:clobber, 'gem:package'] do |t|
|
10
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
11
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
12
|
+
pkg = "pkg/#{PROJ.gem._spec.full_name}"
|
13
|
+
|
14
|
+
if $DEBUG then
|
15
|
+
puts "release_id = rf.add_release #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
|
16
|
+
puts "rf.add_file #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
|
17
|
+
end
|
18
|
+
|
19
|
+
rf = RubyForge.new
|
20
|
+
rf.configure rescue nil
|
21
|
+
puts 'Logging in'
|
22
|
+
rf.login
|
23
|
+
|
24
|
+
c = rf.userconfig
|
25
|
+
c['release_notes'] = PROJ.description if PROJ.description
|
26
|
+
c['release_changes'] = PROJ.changes if PROJ.changes
|
27
|
+
c['preformatted'] = true
|
28
|
+
|
29
|
+
files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
|
30
|
+
(PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
|
31
|
+
"#{pkg}.gem"].compact
|
32
|
+
|
33
|
+
puts "Releasing #{PROJ.name} v. #{PROJ.version}"
|
34
|
+
rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
|
35
|
+
end
|
36
|
+
end # namespace :gem
|
37
|
+
|
38
|
+
|
39
|
+
namespace :doc do
|
40
|
+
desc "Publish RDoc to RubyForge"
|
41
|
+
task :release => %w(doc:clobber_rdoc doc:rdoc) do
|
42
|
+
config = YAML.load(
|
43
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
44
|
+
)
|
45
|
+
|
46
|
+
host = "#{config['username']}@rubyforge.org"
|
47
|
+
remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
|
48
|
+
remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
|
49
|
+
local_dir = PROJ.rdoc.dir
|
50
|
+
|
51
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
52
|
+
end
|
53
|
+
end # namespace :doc
|
54
|
+
|
55
|
+
end # if HAVE_RUBYFORGE
|
56
|
+
|
57
|
+
# EOF
|
data/tasks/setup.rb
ADDED
@@ -0,0 +1,268 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/clean'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
class OpenStruct; undef :gem; end
|
10
|
+
|
11
|
+
PROJ = OpenStruct.new(
|
12
|
+
# Project Defaults
|
13
|
+
:name => nil,
|
14
|
+
:summary => nil,
|
15
|
+
:description => nil,
|
16
|
+
:changes => nil,
|
17
|
+
:authors => nil,
|
18
|
+
:email => nil,
|
19
|
+
:url => "\000",
|
20
|
+
:version => ENV['VERSION'] || '0.0.0',
|
21
|
+
:exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
|
22
|
+
:release_name => ENV['RELEASE'],
|
23
|
+
|
24
|
+
# System Defaults
|
25
|
+
:ruby_opts => %w(-w),
|
26
|
+
:libs => [],
|
27
|
+
:history_file => 'History.txt',
|
28
|
+
:manifest_file => 'Manifest.txt',
|
29
|
+
:readme_file => 'README.txt',
|
30
|
+
|
31
|
+
# Announce
|
32
|
+
:ann => OpenStruct.new(
|
33
|
+
:file => 'announcement.txt',
|
34
|
+
:text => nil,
|
35
|
+
:paragraphs => [],
|
36
|
+
:email => {
|
37
|
+
:from => nil,
|
38
|
+
:to => %w(ruby-talk@ruby-lang.org),
|
39
|
+
:server => 'localhost',
|
40
|
+
:port => 25,
|
41
|
+
:domain => ENV['HOSTNAME'],
|
42
|
+
:acct => nil,
|
43
|
+
:passwd => nil,
|
44
|
+
:authtype => :plain
|
45
|
+
}
|
46
|
+
),
|
47
|
+
|
48
|
+
# Gem Packaging
|
49
|
+
:gem => OpenStruct.new(
|
50
|
+
:dependencies => [],
|
51
|
+
:executables => nil,
|
52
|
+
:extensions => FileList['ext/**/extconf.rb'],
|
53
|
+
:files => nil,
|
54
|
+
:need_tar => true,
|
55
|
+
:need_zip => false,
|
56
|
+
:extras => {}
|
57
|
+
),
|
58
|
+
|
59
|
+
# File Annotations
|
60
|
+
:notes => OpenStruct.new(
|
61
|
+
:exclude => %w(^tasks/setup\.rb$),
|
62
|
+
:extensions => %w(.txt .rb .erb) << '',
|
63
|
+
:tags => %w(FIXME OPTIMIZE TODO)
|
64
|
+
),
|
65
|
+
|
66
|
+
# Rcov
|
67
|
+
:rcov => OpenStruct.new(
|
68
|
+
:dir => 'coverage',
|
69
|
+
:opts => %w[--sort coverage -T],
|
70
|
+
:threshold => 90.0,
|
71
|
+
:threshold_exact => false
|
72
|
+
),
|
73
|
+
|
74
|
+
# Rdoc
|
75
|
+
:rdoc => OpenStruct.new(
|
76
|
+
:opts => [],
|
77
|
+
:include => %w(^lib/ ^bin/ ^ext/ \.txt$),
|
78
|
+
:exclude => %w(extconf\.rb$),
|
79
|
+
:main => nil,
|
80
|
+
:dir => 'doc',
|
81
|
+
:remote_dir => nil
|
82
|
+
),
|
83
|
+
|
84
|
+
# Rubyforge
|
85
|
+
:rubyforge => OpenStruct.new(
|
86
|
+
:name => "\000"
|
87
|
+
),
|
88
|
+
|
89
|
+
# Rspec
|
90
|
+
:spec => OpenStruct.new(
|
91
|
+
:files => FileList['spec/**/*_spec.rb'],
|
92
|
+
:opts => []
|
93
|
+
),
|
94
|
+
|
95
|
+
# Subversion Repository
|
96
|
+
:svn => OpenStruct.new(
|
97
|
+
:root => nil,
|
98
|
+
:path => '',
|
99
|
+
:trunk => 'trunk',
|
100
|
+
:tags => 'tags',
|
101
|
+
:branches => 'branches'
|
102
|
+
),
|
103
|
+
|
104
|
+
# Test::Unit
|
105
|
+
:test => OpenStruct.new(
|
106
|
+
:files => FileList['test/**/test_*.rb'],
|
107
|
+
:file => 'test/all.rb',
|
108
|
+
:opts => []
|
109
|
+
)
|
110
|
+
)
|
111
|
+
|
112
|
+
# Load the other rake files in the tasks folder
|
113
|
+
rakefiles = Dir.glob('tasks/*.rake').sort
|
114
|
+
rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
|
115
|
+
import(*rakefiles)
|
116
|
+
|
117
|
+
# Setup the project libraries
|
118
|
+
%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
|
119
|
+
|
120
|
+
# Setup some constants
|
121
|
+
WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
|
122
|
+
|
123
|
+
DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
|
124
|
+
|
125
|
+
def quiet( &block )
|
126
|
+
io = [STDOUT.dup, STDERR.dup]
|
127
|
+
STDOUT.reopen DEV_NULL
|
128
|
+
STDERR.reopen DEV_NULL
|
129
|
+
block.call
|
130
|
+
ensure
|
131
|
+
STDOUT.reopen io.first
|
132
|
+
STDERR.reopen io.last
|
133
|
+
$stdout, $stderr = STDOUT, STDERR
|
134
|
+
end
|
135
|
+
|
136
|
+
DIFF = if WIN32 then 'diff.exe'
|
137
|
+
else
|
138
|
+
if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
|
139
|
+
else 'diff' end
|
140
|
+
end unless defined? DIFF
|
141
|
+
|
142
|
+
SUDO = if WIN32 then ''
|
143
|
+
else
|
144
|
+
if quiet {system 'which sudo'} then 'sudo'
|
145
|
+
else '' end
|
146
|
+
end
|
147
|
+
|
148
|
+
RCOV = WIN32 ? 'rcov.bat' : 'rcov'
|
149
|
+
RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
|
150
|
+
GEM = WIN32 ? 'gem.bat' : 'gem'
|
151
|
+
|
152
|
+
%w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
|
153
|
+
begin
|
154
|
+
require lib
|
155
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
|
156
|
+
rescue LoadError
|
157
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
|
161
|
+
system("svn --version 2>&1 > #{DEV_NULL}"))
|
162
|
+
HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
|
163
|
+
system("git --version 2>&1 > #{DEV_NULL}"))
|
164
|
+
|
165
|
+
# Reads a file at +path+ and spits out an array of the +paragraphs+
|
166
|
+
# specified.
|
167
|
+
#
|
168
|
+
# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
169
|
+
# summary, *description = paragraphs_of('README.txt', 3, 3..8)
|
170
|
+
#
|
171
|
+
def paragraphs_of( path, *paragraphs )
|
172
|
+
title = String === paragraphs.first ? paragraphs.shift : nil
|
173
|
+
ary = File.read(path).delete("\r").split(/\n\n+/)
|
174
|
+
|
175
|
+
result = if title
|
176
|
+
tmp, matching = [], false
|
177
|
+
rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
|
178
|
+
paragraphs << (0..-1) if paragraphs.empty?
|
179
|
+
|
180
|
+
ary.each do |val|
|
181
|
+
if val =~ rgxp
|
182
|
+
break if matching
|
183
|
+
matching = true
|
184
|
+
rgxp = %r/^=+/i
|
185
|
+
elsif matching
|
186
|
+
tmp << val
|
187
|
+
end
|
188
|
+
end
|
189
|
+
tmp
|
190
|
+
else ary end
|
191
|
+
|
192
|
+
result.values_at(*paragraphs)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Adds the given gem _name_ to the current project's dependency list. An
|
196
|
+
# optional gem _version_ can be given. If omitted, the newest gem version
|
197
|
+
# will be used.
|
198
|
+
#
|
199
|
+
def depend_on( name, version = nil )
|
200
|
+
spec = Gem.source_index.find_name(name).last
|
201
|
+
version = spec.version.to_s if version.nil? and !spec.nil?
|
202
|
+
|
203
|
+
PROJ.gem.dependencies << case version
|
204
|
+
when nil; [name]
|
205
|
+
when %r/^\d/; [name, ">= #{version}"]
|
206
|
+
else [name, version] end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Adds the given arguments to the include path if they are not already there
|
210
|
+
#
|
211
|
+
def ensure_in_path( *args )
|
212
|
+
args.each do |path|
|
213
|
+
path = File.expand_path(path)
|
214
|
+
$:.unshift(path) if test(?d, path) and not $:.include?(path)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Find a rake task using the task name and remove any description text. This
|
219
|
+
# will prevent the task from being displayed in the list of available tasks.
|
220
|
+
#
|
221
|
+
def remove_desc_for_task( names )
|
222
|
+
Array(names).each do |task_name|
|
223
|
+
task = Rake.application.tasks.find {|t| t.name == task_name}
|
224
|
+
next if task.nil?
|
225
|
+
task.instance_variable_set :@comment, nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Change working directories to _dir_, call the _block_ of code, and then
|
230
|
+
# change back to the original working directory (the current directory when
|
231
|
+
# this method was called).
|
232
|
+
#
|
233
|
+
def in_directory( dir, &block )
|
234
|
+
curdir = pwd
|
235
|
+
begin
|
236
|
+
cd dir
|
237
|
+
return block.call
|
238
|
+
ensure
|
239
|
+
cd curdir
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Scans the current working directory and creates a list of files that are
|
244
|
+
# candidates to be in the manifest.
|
245
|
+
#
|
246
|
+
def manifest_files
|
247
|
+
files = []
|
248
|
+
exclude = Regexp.new(PROJ.exclude.join('|'))
|
249
|
+
Find.find '.' do |path|
|
250
|
+
path.sub! %r/^(\.\/|\/)/o, ''
|
251
|
+
next unless test ?f, path
|
252
|
+
next if path =~ exclude
|
253
|
+
files << path
|
254
|
+
end
|
255
|
+
files.sort!
|
256
|
+
end
|
257
|
+
|
258
|
+
# We need a "valid" method thtat determines if a string is suitable for use
|
259
|
+
# in the gem specification.
|
260
|
+
#
|
261
|
+
class Object
|
262
|
+
def valid?
|
263
|
+
return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
|
264
|
+
return false
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# EOF
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_SPEC_RAKE_SPECTASK
|
4
|
+
require 'spec/rake/verify_rcov'
|
5
|
+
|
6
|
+
namespace :spec do
|
7
|
+
|
8
|
+
desc 'Run all specs with basic output'
|
9
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
10
|
+
t.ruby_opts = PROJ.ruby_opts
|
11
|
+
t.spec_opts = PROJ.spec.opts
|
12
|
+
t.spec_files = PROJ.spec.files
|
13
|
+
t.libs += PROJ.libs
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Run all specs with text output'
|
17
|
+
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
18
|
+
t.ruby_opts = PROJ.ruby_opts
|
19
|
+
t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
|
20
|
+
t.spec_files = PROJ.spec.files
|
21
|
+
t.libs += PROJ.libs
|
22
|
+
end
|
23
|
+
|
24
|
+
if HAVE_RCOV
|
25
|
+
desc 'Run all specs with RCov'
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
27
|
+
t.ruby_opts = PROJ.ruby_opts
|
28
|
+
t.spec_opts = PROJ.spec.opts
|
29
|
+
t.spec_files = PROJ.spec.files
|
30
|
+
t.libs += PROJ.libs
|
31
|
+
t.rcov = true
|
32
|
+
t.rcov_dir = PROJ.rcov.dir
|
33
|
+
t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
|
34
|
+
end
|
35
|
+
|
36
|
+
RCov::VerifyTask.new(:verify) do |t|
|
37
|
+
t.threshold = PROJ.rcov.threshold
|
38
|
+
t.index_html = File.join(PROJ.rcov.dir, 'index.html')
|
39
|
+
t.require_exact_threshold = PROJ.rcov.threshold_exact
|
40
|
+
end
|
41
|
+
|
42
|
+
task :verify => :rcov
|
43
|
+
remove_desc_for_task %w(spec:clobber_rcov)
|
44
|
+
end
|
45
|
+
|
46
|
+
end # namespace :spec
|
47
|
+
|
48
|
+
desc 'Alias to spec:run'
|
49
|
+
task :spec => 'spec:run'
|
50
|
+
|
51
|
+
task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
|
52
|
+
|
53
|
+
end # if HAVE_SPEC_RAKE_SPECTASK
|
54
|
+
|
55
|
+
# EOF
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: expiration-date
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Pease
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-22 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Wandering the grocery aisle the other day I saw a package of bacon with a neon green sticker screaming for all to hear "THIS BACON ONLY COSTS ONE DOLLAR!!!". Screaming bacon always intrigues me, so I grabbed the nearest store manager. He works at the coffee shop next door, but when I told him about the screaming bacon he had to come and see for himself. "Oh, it's a manager's special" he told me. "When products get too old the manager will reduce the price so they sell more quickly. This allows new products to be put on the shelves, and the store can make some money instead of throwing out the expired products". I stared at him blankly. He wandered back to the coffee shop and had a latte. I continued to stand there thinking about expiring products and how Ruby could benefit from neon green stickers and stale bacon. Eventually the grocery store manager came by and asked me if everything was okay. I grabbed him by the collar, pointed at the bacon and yelled "DO YOU KNOW WHAT THIS MEANS!?!?". I ran from the store, grabbed my laptop, and whipped up this little gem. EXPIRATION DATE (now with more neon green). Now ruby can expire it's bacon, too, just like the grocery store, and make room for more bacon from the delivery truck.
|
17
|
+
email: tim.pease@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- History.txt
|
24
|
+
- README.txt
|
25
|
+
files:
|
26
|
+
- History.txt
|
27
|
+
- Manifest.txt
|
28
|
+
- README.txt
|
29
|
+
- Rakefile
|
30
|
+
- lib/expiration-date.rb
|
31
|
+
- spec/expiration-date_spec.rb
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
- tasks/ann.rake
|
34
|
+
- tasks/bones.rake
|
35
|
+
- tasks/gem.rake
|
36
|
+
- tasks/git.rake
|
37
|
+
- tasks/manifest.rake
|
38
|
+
- tasks/notes.rake
|
39
|
+
- tasks/post_load.rake
|
40
|
+
- tasks/rdoc.rake
|
41
|
+
- tasks/rubyforge.rake
|
42
|
+
- tasks/setup.rb
|
43
|
+
- tasks/spec.rake
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://codeforpeople.rubyforge.org/expiration-date
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.txt
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: codeforpeople
|
67
|
+
rubygems_version: 1.2.0
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: auto-expiring / auto-refreshing attributes for your ruby classes
|
71
|
+
test_files: []
|
72
|
+
|