bones 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +20 -25
  3. data/README.txt +114 -83
  4. data/Rakefile +7 -6
  5. data/data/Rakefile.erb +7 -1
  6. data/data/bin/NAME.erb +1 -1
  7. data/data/lib/NAME.rb.erb +4 -11
  8. data/data/spec/NAME_spec.rb.erb +0 -1
  9. data/data/spec/spec_helper.rb.erb +0 -1
  10. data/lib/bones.rb +21 -8
  11. data/lib/bones/annotation_extractor.rb +1 -2
  12. data/lib/bones/debug.rb +0 -1
  13. data/lib/bones/main.rb +183 -109
  14. data/lib/bones/smtp_tls.rb +0 -1
  15. data/{data → lib/bones}/tasks/ann.rake +0 -1
  16. data/{data → lib/bones}/tasks/bones.rake +0 -1
  17. data/lib/bones/tasks/gem.rake +192 -0
  18. data/{data → lib/bones}/tasks/git.rake +0 -1
  19. data/{data → lib/bones}/tasks/manifest.rake +3 -4
  20. data/{data → lib/bones}/tasks/notes.rake +0 -1
  21. data/{data → lib/bones}/tasks/post_load.rake +2 -2
  22. data/{data → lib/bones}/tasks/rdoc.rake +0 -1
  23. data/{data → lib/bones}/tasks/rubyforge.rake +2 -4
  24. data/{data → lib/bones}/tasks/setup.rb +14 -3
  25. data/{data → lib/bones}/tasks/spec.rake +1 -2
  26. data/{data → lib/bones}/tasks/svn.rake +0 -1
  27. data/{data → lib/bones}/tasks/test.rake +3 -1
  28. data/spec/bones/main_spec.rb +157 -0
  29. data/spec/bones_spec.rb +18 -0
  30. data/spec/data/data/README.txt +0 -0
  31. data/spec/data/data/Rakefile +0 -0
  32. data/spec/data/foo/README.txt +0 -0
  33. data/spec/data/foo/Rakefile +0 -0
  34. data/spec/spec_helper.rb +22 -0
  35. data/tasks/ann.rake +0 -1
  36. data/tasks/bones.rake +0 -1
  37. data/tasks/gem.rake +98 -32
  38. data/tasks/git.rake +0 -1
  39. data/tasks/manifest.rake +3 -4
  40. data/tasks/notes.rake +0 -1
  41. data/tasks/post_load.rake +2 -2
  42. data/tasks/rdoc.rake +0 -1
  43. data/tasks/rubyforge.rake +2 -4
  44. data/tasks/setup.rb +14 -3
  45. data/tasks/spec.rake +1 -2
  46. data/tasks/svn.rake +47 -0
  47. data/tasks/test.rake +3 -1
  48. metadata +40 -17
  49. data/data/tasks/gem.rake +0 -126
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  # This code enables SMTPTLS authentication requireed for sending mail
4
3
  # via the gmail servers. I found this code via a blog entry from James
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  begin
4
3
  require 'bones/smtp_tls'
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  if HAVE_BONES
4
3
 
@@ -0,0 +1,192 @@
1
+
2
+ require 'find'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/user_interaction'
5
+ require 'rubygems/builder'
6
+
7
+ module Bones
8
+ class GemPackageTask < Rake::PackageTask
9
+ # Ruby GEM spec containing the metadata for this package. The
10
+ # name, version and package_files are automatically determined
11
+ # from the GEM spec and don't need to be explicitly provided.
12
+ #
13
+ attr_accessor :gem_spec
14
+
15
+ # Tasks from the Bones gem directory
16
+ attr_reader :bones_files
17
+
18
+ # Create a GEM Package task library. Automatically define the gem
19
+ # if a block is given. If no block is supplied, then +define+
20
+ # needs to be called to define the task.
21
+ #
22
+ def initialize(gem_spec)
23
+ init(gem_spec)
24
+ yield self if block_given?
25
+ define if block_given?
26
+ end
27
+
28
+ # Initialization tasks without the "yield self" or define
29
+ # operations.
30
+ #
31
+ def init(gem)
32
+ super(gem.name, gem.version)
33
+ @gem_spec = gem
34
+ @package_files += gem_spec.files if gem_spec.files
35
+ @bones_files = []
36
+
37
+ local_setup = File.join(Dir.pwd, %w[tasks setup.rb])
38
+ if !test(?e, local_setup)
39
+ Dir.glob(::Bones.path(%w[lib bones tasks *])).each {|fn| bones_files << fn}
40
+ gem_spec.files = (gem_spec.files +
41
+ bones_files.map {|fn| File.join('tasks', File.basename(fn))}).sort
42
+ end
43
+ end
44
+
45
+ # Create the Rake tasks and actions specified by this
46
+ # GemPackageTask. (+define+ is automatically called if a block is
47
+ # given to +new+).
48
+ #
49
+ def define
50
+ super
51
+ task :prereqs
52
+ task :package => ['gem:prereqs', "#{package_dir_path}/#{gem_file}"]
53
+ file "#{package_dir_path}/#{gem_file}" => [package_dir_path] + package_files + bones_files do
54
+ when_writing("Creating GEM") {
55
+ chdir(package_dir_path) do
56
+ Gem::Builder.new(gem_spec).build
57
+ verbose(true) {
58
+ mv gem_file, "../#{gem_file}"
59
+ }
60
+ end
61
+ }
62
+ end
63
+
64
+ file package_dir_path => bones_files do
65
+ mkdir_p package_dir rescue nil
66
+ bones_files.each do |fn|
67
+ base_fn = File.join('tasks', File.basename(fn))
68
+ f = File.join(package_dir_path, base_fn)
69
+ fdir = File.dirname(f)
70
+ mkdir_p(fdir) if !File.exist?(fdir)
71
+ if File.directory?(fn)
72
+ mkdir_p(f)
73
+ else
74
+ raise "file name conflict for '#{base_fn}' (conflicts with '#{fn}')" if test(?e, f)
75
+ safe_ln(fn, f)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ def gem_file
82
+ if @gem_spec.platform == Gem::Platform::RUBY
83
+ "#{package_name}.gem"
84
+ else
85
+ "#{package_name}-#{@gem_spec.platform}.gem"
86
+ end
87
+ end
88
+ end # class GemPackageTask
89
+ end # module Bones
90
+
91
+ namespace :gem do
92
+
93
+ PROJ.gem._spec = Gem::Specification.new do |s|
94
+ s.name = PROJ.name
95
+ s.version = PROJ.version
96
+ s.summary = PROJ.summary
97
+ s.authors = Array(PROJ.authors)
98
+ s.email = PROJ.email
99
+ s.homepage = Array(PROJ.url).first
100
+ s.rubyforge_project = PROJ.rubyforge.name
101
+
102
+ s.description = PROJ.description
103
+
104
+ PROJ.gem.dependencies.each do |dep|
105
+ s.add_dependency(*dep)
106
+ end
107
+
108
+ PROJ.gem.development_dependencies.each do |dep|
109
+ s.add_development_dependency(*dep)
110
+ end
111
+
112
+ s.files = PROJ.gem.files
113
+ s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
114
+ s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
115
+
116
+ s.bindir = 'bin'
117
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
118
+ s.require_paths = dirs unless dirs.empty?
119
+
120
+ incl = Regexp.new(PROJ.rdoc.include.join('|'))
121
+ excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
122
+ excl = Regexp.new(excl.join('|'))
123
+ rdoc_files = PROJ.gem.files.find_all do |fn|
124
+ case fn
125
+ when excl; false
126
+ when incl; true
127
+ else false end
128
+ end
129
+ s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
130
+ s.extra_rdoc_files = rdoc_files
131
+ s.has_rdoc = true
132
+
133
+ if test ?f, PROJ.test.file
134
+ s.test_file = PROJ.test.file
135
+ else
136
+ s.test_files = PROJ.test.files.to_a
137
+ end
138
+
139
+ # Do any extra stuff the user wants
140
+ PROJ.gem.extras.each do |msg, val|
141
+ case val
142
+ when Proc
143
+ val.call(s.send(msg))
144
+ else
145
+ s.send "#{msg}=", val
146
+ end
147
+ end
148
+ end # Gem::Specification.new
149
+
150
+ Bones::GemPackageTask.new(PROJ.gem._spec) do |pkg|
151
+ pkg.need_tar = PROJ.gem.need_tar
152
+ pkg.need_zip = PROJ.gem.need_zip
153
+ end
154
+
155
+ desc 'Show information about the gem'
156
+ task :debug => 'gem:prereqs' do
157
+ puts PROJ.gem._spec.to_ruby
158
+ end
159
+
160
+ desc 'Install the gem'
161
+ task :install => [:clobber, 'gem:package'] do
162
+ sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
163
+
164
+ # use this version of the command for rubygems > 1.0.0
165
+ #sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
166
+ end
167
+
168
+ desc 'Uninstall the gem'
169
+ task :uninstall do
170
+ installed_list = Gem.source_index.find_name(PROJ.name)
171
+ if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
172
+ sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
173
+ end
174
+ end
175
+
176
+ desc 'Reinstall the gem'
177
+ task :reinstall => [:uninstall, :install]
178
+
179
+ desc 'Cleanup the gem'
180
+ task :cleanup do
181
+ sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
182
+ end
183
+ end # namespace :gem
184
+
185
+
186
+ desc 'Alias to gem:package'
187
+ task :gem => 'gem:package'
188
+
189
+ task :clobber => 'gem:clobber_package'
190
+ remove_desc_for_task 'gem:clobber_package'
191
+
192
+ # EOF
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  if HAVE_GIT
4
3
 
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  require 'find'
4
3
 
@@ -15,9 +14,9 @@ namespace :manifest do
15
14
  lines.map! do |line|
16
15
  case line
17
16
  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
17
+ when %r/^@/; ANSICode.blue line
18
+ when %r/^\+/; ANSICode.green line
19
+ when %r/^\-/; ANSICode.red line
21
20
  else line end
22
21
  end
23
22
  end
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  if HAVE_BONES
4
3
 
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  # This file does not define any rake tasks. It is used to load some project
4
3
  # settings if they are not defined by the user.
@@ -10,7 +9,8 @@ PROJ.exclude << ["^#{Regexp.escape(PROJ.ann.file)}$",
10
9
 
11
10
  flatten_arrays = lambda do |this,os|
12
11
  os.instance_variable_get(:@table).each do |key,val|
13
- next if key == :dependencies
12
+ next if key == :dependencies \
13
+ or key == :development_dependencies
14
14
  case val
15
15
  when Array; val.flatten!
16
16
  when OpenStruct; this.call(this,val)
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  require 'rake/rdoctask'
4
3
 
@@ -6,7 +6,7 @@ require 'rake/contrib/sshpublisher'
6
6
 
7
7
  namespace :gem do
8
8
  desc 'Package and upload to RubyForge'
9
- task :release => [:clobber, 'gem:package'] do |t|
9
+ task :release => [:clobber, 'gem'] do |t|
10
10
  v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
11
11
  abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
12
12
  pkg = "pkg/#{PROJ.gem._spec.full_name}"
@@ -26,9 +26,7 @@ namespace :gem do
26
26
  c['release_changes'] = PROJ.changes if PROJ.changes
27
27
  c['preformatted'] = true
28
28
 
29
- files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
30
- (PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
31
- "#{pkg}.gem"].compact
29
+ files = Dir.glob("#{pkg}*.*")
32
30
 
33
31
  puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
32
  rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  require 'rubygems'
4
3
  require 'rake'
@@ -8,6 +7,9 @@ require 'ostruct'
8
7
 
9
8
  class OpenStruct; undef :gem; end
10
9
 
10
+ # TODO: make my own openstruct type object that includes descriptions
11
+ # TODO: use the descriptions to output help on the available bones options
12
+
11
13
  PROJ = OpenStruct.new(
12
14
  # Project Defaults
13
15
  :name => nil,
@@ -48,6 +50,7 @@ PROJ = OpenStruct.new(
48
50
  # Gem Packaging
49
51
  :gem => OpenStruct.new(
50
52
  :dependencies => [],
53
+ :development_dependencies => [],
51
54
  :executables => nil,
52
55
  :extensions => FileList['ext/**/extconf.rb'],
53
56
  :files => nil,
@@ -110,8 +113,10 @@ PROJ = OpenStruct.new(
110
113
  )
111
114
 
112
115
  # 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!
116
+ tasks_dir = File.expand_path(File.dirname(__FILE__))
117
+ post_load_fn = File.join(tasks_dir, 'post_load.rake')
118
+ rakefiles = Dir.glob(File.join(tasks_dir, '*.rake')).sort
119
+ rakefiles.unshift(rakefiles.delete(post_load_fn)).compact!
115
120
  import(*rakefiles)
116
121
 
117
122
  # Setup the project libraries
@@ -162,6 +167,12 @@ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
162
167
  HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
163
168
  system("git --version 2>&1 > #{DEV_NULL}"))
164
169
 
170
+ # Add bones as a development dependency
171
+ #
172
+ if HAVE_BONES
173
+ PROJ.gem.development_dependencies << ['bones', ">= #{Bones::VERSION}"]
174
+ end
175
+
165
176
  # Reads a file at +path+ and spits out an array of the +paragraphs+
166
177
  # specified.
167
178
  #
@@ -1,6 +1,5 @@
1
- # $Id$
2
1
 
3
- if HAVE_SPEC_RAKE_SPECTASK
2
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
4
3
  require 'spec/rake/verify_rcov'
5
4
 
6
5
  namespace :spec do
@@ -1,4 +1,3 @@
1
- # $Id$
2
1
 
3
2
  if HAVE_SVN
4
3
 
@@ -1,5 +1,5 @@
1
- # $Id$
2
1
 
2
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
3
3
  require 'rake/testtask'
4
4
 
5
5
  namespace :test do
@@ -35,4 +35,6 @@ task :test => 'test:run'
35
35
 
36
36
  task :clobber => 'test:clobber_rcov' if HAVE_RCOV
37
37
 
38
+ end
39
+
38
40
  # EOF
@@ -0,0 +1,157 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. spec_helper]))
4
+
5
+ describe Bones::Main do
6
+
7
+ before :each do
8
+ @main = Bones::Main.new
9
+ @skeleton_dir = File.join(@main.mrbones_dir, 'data')
10
+ @skeleton_dir = Bones.path('data') unless test(?e, @skeleton_dir)
11
+ end
12
+
13
+ it 'has some defaults when initialized' do
14
+ @main.options.should == {
15
+ :skeleton_dir => @skeleton_dir,
16
+ :with_tasks => false,
17
+ :verbose => false,
18
+ :name => nil,
19
+ :output_dir => nil,
20
+ :action => nil
21
+ }
22
+ end
23
+
24
+ it 'provides access to the output_dir' do
25
+ @main.output_dir.should be_nil
26
+ @main.options[:output_dir] = 'foo'
27
+ @main.output_dir.should == 'foo'
28
+ end
29
+
30
+ it 'provides access to the skeleton_dir' do
31
+ @main.skeleton_dir.should == @skeleton_dir
32
+ @main.options[:skeleton_dir] = 'bar'
33
+ @main.skeleton_dir.should == 'bar'
34
+ end
35
+
36
+ it 'provides access to the project name' do
37
+ @main.name.should be_nil
38
+ @main.options[:name] = 'baz'
39
+ @main.name.should == 'baz'
40
+ end
41
+
42
+ it 'provides access to the project classname' do
43
+ @main.options[:name] = 'foo-bar'
44
+ @main.classname.should == 'FooBar'
45
+ end
46
+
47
+ it 'determines if a project should be updated' do
48
+ @main.options[:output_dir] = Bones.path
49
+ @main.update?.should == false
50
+
51
+ @main.options[:with_tasks] = true
52
+ @main.update?.should == true
53
+
54
+ @main.options[:output_dir] = Bones.path(%w[foo bar baz buz tmp])
55
+ @main.update?.should == false
56
+ end
57
+
58
+ # ------------------------------------------------------------------------
59
+ describe 'when parsing command line options' do
60
+
61
+ before :each do
62
+ @main.stub!(:mrbones_dir).and_return(Bones.path(%w[spec data]))
63
+ end
64
+
65
+ it 'parses the project name' do
66
+ @main.parse %w[foo-bar]
67
+ @main.name.should == 'foo-bar'
68
+ @main.output_dir.should == 'foo-bar'
69
+ end
70
+
71
+ it 'parses the verbose flag' do
72
+ @main.parse %w[-v foo-bar]
73
+ @main.name.should == 'foo-bar'
74
+ @main.verbose?.should == true
75
+
76
+ @main = Bones::Main.new
77
+ @main.parse %w[--verbose foo-bar]
78
+ @main.name.should == 'foo-bar'
79
+ @main.verbose?.should == true
80
+ end
81
+
82
+ it 'parses the directory flag' do
83
+ @main.parse %w[-d blah foo-bar]
84
+ @main.name.should == 'foo-bar'
85
+ @main.output_dir.should == 'blah'
86
+
87
+ @main = Bones::Main.new
88
+ @main.parse %w[--directory blah foo-bar]
89
+ @main.name.should == 'foo-bar'
90
+ @main.output_dir.should == 'blah'
91
+ end
92
+
93
+ it 'parses the directory flag' do
94
+ @main.parse %w[-d blah foo-bar]
95
+ @main.name.should == 'foo-bar'
96
+ @main.output_dir.should == 'blah'
97
+
98
+ @main = Bones::Main.new
99
+ @main.parse %w[--directory blah foo-bar]
100
+ @main.name.should == 'foo-bar'
101
+ @main.output_dir.should == 'blah'
102
+ end
103
+
104
+ it 'parses the skeleton to use flag' do
105
+ @main.stub!(:mrbones_dir).and_return(Bones.path(%w[spec data]))
106
+ @main.parse %w[-s data foo-bar]
107
+ @main.name.should == 'foo-bar'
108
+ @main.skeleton_dir.should == Bones.path(%w[spec data data])
109
+
110
+ @main = Bones::Main.new
111
+ @main.stub!(:mrbones_dir).and_return(Bones.path(%w[spec data]))
112
+ @main.parse %w[--skeleton foo foo-bar]
113
+ @main.name.should == 'foo-bar'
114
+ @main.skeleton_dir.should == Bones.path(%w[spec data foo])
115
+ end
116
+
117
+ it 'parses the with-tasks flag' do
118
+ @main.parse %w[--with-tasks foo-bar]
119
+ @main.name.should == 'foo-bar'
120
+ @main.with_tasks?.should == true
121
+ end
122
+
123
+ it 'parses the freeze flag' do
124
+ @main.parse %w[--freeze]
125
+ @main.name.should be_nil
126
+ @main.options[:action].should == :freeze
127
+
128
+ @main = Bones::Main.new
129
+ @main.parse %w[--freeze foo-bar]
130
+ @main.name.should == 'foo-bar'
131
+ @main.options[:action].should == :freeze
132
+ end
133
+
134
+ it 'parses the unfreeze flag' do
135
+ @main.parse %w[--unfreeze]
136
+ @main.name.should be_nil
137
+ @main.options[:action].should == :unfreeze
138
+ end
139
+
140
+ it 'parses the info flag' do
141
+ @main.parse %w[--info]
142
+ @main.name.should be_nil
143
+ @main.options[:action].should == :info
144
+
145
+ @main = Bones::Main.new
146
+ @main.parse %w[-i]
147
+ @main.name.should be_nil
148
+ @main.options[:action].should == :info
149
+ end
150
+ end
151
+
152
+ # ------------------------------------------------------------------------
153
+ #describe 'when archiving tasks'
154
+
155
+ end # describe Bones::Main
156
+
157
+ # EOF