bones 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/Manifest.txt +22 -11
- data/README.rdoc +34 -10
- data/Rakefile +2 -2
- data/bin/bones +1 -1
- data/bones.gemspec +40 -0
- data/data/{History.txt.erb → History.txt.bns} +0 -0
- data/data/{README.txt.erb → README.txt.bns} +0 -0
- data/data/{Rakefile.erb → Rakefile.bns} +5 -1
- data/data/bin/{NAME.erb → NAME.bns} +0 -0
- data/data/lib/NAME.rb.bns +49 -0
- data/data/spec/{NAME_spec.rb.erb → NAME_spec.rb.bns} +0 -0
- data/data/spec/{spec_helper.rb.erb → spec_helper.rb.bns} +0 -0
- data/lib/bones.rb +3 -1
- data/lib/bones/app.rb +92 -0
- data/lib/bones/app/command.rb +130 -0
- data/lib/bones/app/create_command.rb +87 -0
- data/lib/bones/app/file_manager.rb +176 -0
- data/lib/bones/app/freeze_command.rb +72 -0
- data/lib/bones/app/info_command.rb +58 -0
- data/lib/bones/app/unfreeze_command.rb +53 -0
- data/lib/bones/app/update_command.rb +47 -0
- data/lib/bones/tasks/gem.rake +11 -2
- data/spec/bones/app/file_manager_spec.rb +150 -0
- data/spec/bones/app_spec.rb +97 -0
- data/spec/data/data/NAME/NAME.rb.bns +5 -0
- data/spec/data/data/README.txt.bns +48 -0
- data/spec/data/data/Rakefile.bns +30 -0
- data/{data/lib/NAME.rb.erb → spec/data/data/lib/NAME.rb.bns} +0 -0
- data/spec/spec_helper.rb +22 -0
- data/tasks/gem.rake +11 -2
- metadata +24 -14
- data/lib/bones/main.rb +0 -380
- data/spec/bones/main_spec.rb +0 -157
- data/spec/data/data/README.txt +0 -0
- data/spec/data/data/Rakefile +0 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
module Bones
|
3
|
+
class App
|
4
|
+
|
5
|
+
class UpdateCommand < Command
|
6
|
+
|
7
|
+
def run( args )
|
8
|
+
parse args
|
9
|
+
|
10
|
+
raise "'#{output_dir}' does not exist" unless test(?e, output_dir)
|
11
|
+
copy_tasks(File.join(output_dir, 'tasks'))
|
12
|
+
|
13
|
+
msg = "Updated tasks in directory '#{output_dir}'"
|
14
|
+
@out.puts msg
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse( args )
|
18
|
+
std_opts = standard_options
|
19
|
+
|
20
|
+
opts = OptionParser.new
|
21
|
+
opts.banner = 'Usage: bones update <directory>'
|
22
|
+
|
23
|
+
opts.separator ''
|
24
|
+
opts.separator ' Copy the Mr Bones rake tasks into the project directory'
|
25
|
+
|
26
|
+
opts.separator ''
|
27
|
+
opts.separator ' Common Options:'
|
28
|
+
opts.on_tail( '-h', '--help', 'show this message' ) {
|
29
|
+
@out.puts opts
|
30
|
+
exit
|
31
|
+
}
|
32
|
+
|
33
|
+
# parse the command line arguments
|
34
|
+
opts.parse! args
|
35
|
+
options[:output_dir] = args.empty? ? nil : args.join('_')
|
36
|
+
|
37
|
+
if output_dir.nil?
|
38
|
+
@out.puts opts
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end # class CreateCommand
|
44
|
+
end # class App
|
45
|
+
end # module Bones
|
46
|
+
|
47
|
+
# EOF
|
data/lib/bones/tasks/gem.rake
CHANGED
@@ -37,8 +37,6 @@ class GemPackageTask < Rake::PackageTask
|
|
37
37
|
local_setup = File.join(Dir.pwd, %w[tasks setup.rb])
|
38
38
|
if !test(?e, local_setup)
|
39
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
40
|
end
|
43
41
|
end
|
44
42
|
|
@@ -63,6 +61,10 @@ class GemPackageTask < Rake::PackageTask
|
|
63
61
|
|
64
62
|
file package_dir_path => bones_files do
|
65
63
|
mkdir_p package_dir rescue nil
|
64
|
+
|
65
|
+
gem_spec.files = (gem_spec.files +
|
66
|
+
bones_files.map {|fn| File.join('tasks', File.basename(fn))}).sort
|
67
|
+
|
66
68
|
bones_files.each do |fn|
|
67
69
|
base_fn = File.join('tasks', File.basename(fn))
|
68
70
|
f = File.join(package_dir_path, base_fn)
|
@@ -157,6 +159,13 @@ namespace :gem do
|
|
157
159
|
puts PROJ.gem._spec.to_ruby
|
158
160
|
end
|
159
161
|
|
162
|
+
desc 'Write the gemspec '
|
163
|
+
task :spec => 'gem:prereqs' do
|
164
|
+
File.open("#{PROJ.name}.gemspec", 'w') do |f|
|
165
|
+
f.write PROJ.gem._spec.to_ruby
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
160
169
|
desc 'Install the gem'
|
161
170
|
task :install => [:clobber, 'gem:package'] do
|
162
171
|
sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
|
@@ -0,0 +1,150 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
|
4
|
+
|
5
|
+
# --------------------------------------------------------------------------
|
6
|
+
describe Bones::App::FileManager do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@fm = Bones::App::FileManager.new
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
FileUtils.rm_rf(@fm.destination) if @fm.destination
|
14
|
+
FileUtils.rm_rf(@fm.archive) if @fm.archive
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a configurable source" do
|
18
|
+
@fm.source.should be_nil
|
19
|
+
|
20
|
+
@fm.source = '/home/user/.mrbones/data'
|
21
|
+
@fm.source.should == '/home/user/.mrbones/data'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have a configurable destination" do
|
25
|
+
@fm.destination.should be_nil
|
26
|
+
|
27
|
+
@fm.destination = 'my_new_app'
|
28
|
+
@fm.destination.should == 'my_new_app'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set the archive directory when the destination is set" do
|
32
|
+
@fm.archive.should be_nil
|
33
|
+
|
34
|
+
@fm.destination = 'my_new_app'
|
35
|
+
@fm.archive.should == 'my_new_app.archive'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return a list of files to copy" do
|
39
|
+
@fm.source = Bones.path 'data'
|
40
|
+
|
41
|
+
ary = @fm._files_to_copy
|
42
|
+
ary.length.should == 9
|
43
|
+
|
44
|
+
ary.should == %w[
|
45
|
+
History.txt.bns
|
46
|
+
Manifest.txt
|
47
|
+
README.txt.bns
|
48
|
+
Rakefile.bns
|
49
|
+
bin/NAME.bns
|
50
|
+
lib/NAME.rb.bns
|
51
|
+
spec/NAME_spec.rb.bns
|
52
|
+
spec/spec_helper.rb.bns
|
53
|
+
test/test_NAME.rb
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should archive the destination directory if it exists" do
|
58
|
+
@fm.destination = Bones.path(%w[spec data bar])
|
59
|
+
test(?e, @fm.destination).should == false
|
60
|
+
test(?e, @fm.archive).should == false
|
61
|
+
|
62
|
+
FileUtils.mkdir @fm.destination
|
63
|
+
@fm.archive_destination
|
64
|
+
test(?e, @fm.destination).should == false
|
65
|
+
test(?e, @fm.archive).should == true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should rename files and folders containing 'NAME'" do
|
69
|
+
@fm.source = Bones.path(%w[spec data data])
|
70
|
+
@fm.destination = Bones.path(%w[spec data bar])
|
71
|
+
@fm.copy
|
72
|
+
|
73
|
+
@fm._rename(File.join(@fm.destination, 'NAME'), 'tirion')
|
74
|
+
|
75
|
+
dir = File.join(@fm.destination, 'tirion')
|
76
|
+
test(?d, dir).should == true
|
77
|
+
test(?f, File.join(dir, 'tirion.rb.bns')).should == true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should raise an error when renaming an existing file or folder" do
|
81
|
+
@fm.source = Bones.path(%w[spec data data])
|
82
|
+
@fm.destination = Bones.path(%w[spec data bar])
|
83
|
+
@fm.copy
|
84
|
+
|
85
|
+
lambda {@fm._rename(File.join(@fm.destination, 'NAME'), 'lib')}.
|
86
|
+
should raise_error(RuntimeError)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should perform ERb templating on '.bns' files" do
|
90
|
+
@fm.source = Bones.path(%w[spec data data])
|
91
|
+
@fm.destination = Bones.path(%w[spec data bar])
|
92
|
+
@fm.copy
|
93
|
+
@fm.finalize('foo_bar')
|
94
|
+
|
95
|
+
dir = @fm.destination
|
96
|
+
test(?e, File.join(dir, 'Rakefile.bns')).should == false
|
97
|
+
test(?e, File.join(dir, 'README.txt.bns')).should == false
|
98
|
+
test(?e, File.join(dir, %w[foo_bar foo_bar.rb.bns])).should == false
|
99
|
+
|
100
|
+
test(?e, File.join(dir, 'Rakefile')).should == true
|
101
|
+
test(?e, File.join(dir, 'README.txt')).should == true
|
102
|
+
test(?e, File.join(dir, %w[foo_bar foo_bar.rb])).should == true
|
103
|
+
|
104
|
+
txt = File.read(File.join(@fm.destination, %w[foo_bar foo_bar.rb]))
|
105
|
+
txt.should == <<-TXT
|
106
|
+
module FooBar
|
107
|
+
def self.foo_bar
|
108
|
+
p 'just a test'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
TXT
|
112
|
+
end
|
113
|
+
|
114
|
+
# ------------------------------------------------------------------------
|
115
|
+
describe 'when configured with a repository as a source' do
|
116
|
+
|
117
|
+
it "should recognize a git repository" do
|
118
|
+
@fm.source = 'git://github.com/TwP/bones.git'
|
119
|
+
@fm.repository.should == :git
|
120
|
+
|
121
|
+
@fm.source = 'git://github.com/TwP/bones.git/'
|
122
|
+
@fm.repository.should == :git
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should recognize an svn repository" do
|
126
|
+
@fm.source = 'file:///home/user/svn/ruby/trunk/apc'
|
127
|
+
@fm.repository.should == :svn
|
128
|
+
|
129
|
+
@fm.source = 'http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8'
|
130
|
+
@fm.repository.should == :svn
|
131
|
+
|
132
|
+
@fm.source = 'https://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8'
|
133
|
+
@fm.repository.should == :svn
|
134
|
+
|
135
|
+
@fm.source = 'svn://10.10.10.10/project/trunk'
|
136
|
+
@fm.repository.should == :svn
|
137
|
+
|
138
|
+
@fm.source = 'svn+ssh://10.10.10.10/project/trunk'
|
139
|
+
@fm.repository.should == :svn
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return nil if the source is not a repository" do
|
143
|
+
@fm.source = '/some/directory/on/your/hard/drive'
|
144
|
+
@fm.repository.should == nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
# EOF
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. spec_helper]))
|
4
|
+
|
5
|
+
class Runner
|
6
|
+
attr_accessor :name
|
7
|
+
def run(*a, &b) nil; end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Bones::App do
|
11
|
+
|
12
|
+
before :all do
|
13
|
+
@out = StringIO.new
|
14
|
+
@err = StringIO.new
|
15
|
+
end
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
@runner = Runner.new
|
19
|
+
@app = Bones::App.new(@out, @err)
|
20
|
+
|
21
|
+
Bones::App::CreateCommand.stub!(:new).
|
22
|
+
and_return {@runner.name = :create; @runner}
|
23
|
+
Bones::App::UpdateCommand.stub!(:new).
|
24
|
+
and_return {@runner.name = :update; @runner}
|
25
|
+
Bones::App::FreezeCommand.stub!(:new).
|
26
|
+
and_return {@runner.name = :freeze; @runner}
|
27
|
+
Bones::App::UnfreezeCommand.stub!(:new).
|
28
|
+
and_return {@runner.name = :unfreeze; @runner}
|
29
|
+
Bones::App::InfoCommand.stub!(:new).
|
30
|
+
and_return {@runner.name = :info; @runner}
|
31
|
+
end
|
32
|
+
|
33
|
+
after :each do
|
34
|
+
@out.clear
|
35
|
+
@err.clear
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should provide a create command' do
|
39
|
+
@app.run %w[create]
|
40
|
+
@runner.name.should == :create
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should provide an update command' do
|
44
|
+
@app.run %w[update]
|
45
|
+
@runner.name.should == :update
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should provide a freeze command' do
|
49
|
+
@app.run %w[freeze]
|
50
|
+
@runner.name.should == :freeze
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should provide an unfreeze command' do
|
54
|
+
@app.run %w[unfreeze]
|
55
|
+
@runner.name.should == :unfreeze
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should provide an info command' do
|
59
|
+
@app.run %w[info]
|
60
|
+
@runner.name.should == :info
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should provide a help command' do
|
64
|
+
@app.run %w[--help]
|
65
|
+
@out.readline
|
66
|
+
@out.readline.should match(%r/^ Mr Bones is a handy tool that builds/)
|
67
|
+
@out.clear
|
68
|
+
|
69
|
+
@app.run %w[-h]
|
70
|
+
@out.readline
|
71
|
+
@out.readline.should match(%r/^ Mr Bones is a handy tool that builds/)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should default to the help message if no command is given' do
|
75
|
+
@app.run []
|
76
|
+
@out.readline
|
77
|
+
@out.readline.should match(%r/^ Mr Bones is a handy tool that builds/)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should report an error for unrecognized commands' do
|
81
|
+
lambda {@app.run %w[foo]}.should raise_error(SystemExit)
|
82
|
+
@err.readline.should == 'ERROR: While executing bones ... (RuntimeError)'
|
83
|
+
@err.readline.should == ' Unknown command "foo"'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should report a version number' do
|
87
|
+
@app.run %w[--version]
|
88
|
+
@out.readline.should == "Mr Bones #{Bones::VERSION}"
|
89
|
+
@out.clear
|
90
|
+
|
91
|
+
@app.run %w[-v]
|
92
|
+
@out.readline.should == "Mr Bones #{Bones::VERSION}"
|
93
|
+
end
|
94
|
+
|
95
|
+
end # describe Bones::App
|
96
|
+
|
97
|
+
# EOF
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<%= name %>
|
2
|
+
by FIXME (your name)
|
3
|
+
FIXME (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIXME (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIXME (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIXME (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIXME (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIXME (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 FIXME (different license?)
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,30 @@
|
|
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 '<%= name %>'
|
18
|
+
|
19
|
+
task :default => 'spec:run'
|
20
|
+
|
21
|
+
PROJ.name = '<%= name %>'
|
22
|
+
PROJ.authors = 'FIXME (who is writing this software)'
|
23
|
+
PROJ.email = 'FIXME (your e-mail)'
|
24
|
+
PROJ.url = 'FIXME (project homepage)'
|
25
|
+
PROJ.version = <%= classname %>::VERSION
|
26
|
+
PROJ.rubyforge.name = '<%= name %>'
|
27
|
+
|
28
|
+
PROJ.spec.opts << '--color'
|
29
|
+
|
30
|
+
# EOF
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
unless defined? BONES_SPEC_HELPER
|
4
4
|
BONES_SPEC_HELPER = true
|
5
5
|
|
6
|
+
require 'stringio'
|
6
7
|
require File.expand_path(
|
7
8
|
File.join(File.dirname(__FILE__), %w[.. lib bones]))
|
8
9
|
|
@@ -17,6 +18,27 @@ Spec::Runner.configure do |config|
|
|
17
18
|
# config.mock_with :rr
|
18
19
|
end
|
19
20
|
|
21
|
+
class StringIO
|
22
|
+
alias :_readline :readline
|
23
|
+
def readline
|
24
|
+
@_pos ||= 0
|
25
|
+
seek @_pos
|
26
|
+
begin
|
27
|
+
_line = _readline
|
28
|
+
@_pos = tell
|
29
|
+
_line.rstrip
|
30
|
+
rescue EOFError
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def clear
|
36
|
+
truncate 0
|
37
|
+
seek 0
|
38
|
+
@_pos = 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
20
42
|
end # unless defined?
|
21
43
|
|
22
44
|
# EOF
|