shipyard 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/shipyard +18 -1
- data/lib/shipyard/builder.rb +16 -5
- data/lib/shipyard/context.rb +4 -4
- data/lib/shipyard/manifest.rb +6 -7
- data/spec/context_spec.rb +7 -8
- data/spec/manifest_spec.rb +4 -5
- metadata +40 -13
data/bin/shipyard
CHANGED
@@ -3,5 +3,22 @@
|
|
3
3
|
$:.unshift(File.dirname(__FILE__) + '/../lib/')
|
4
4
|
require 'shipyard'
|
5
5
|
|
6
|
-
|
6
|
+
MANIFEST_FILE = 'Manifest'
|
7
|
+
|
8
|
+
def usage
|
9
|
+
puts <<-END
|
10
|
+
Usage: shipyard <table name>
|
11
|
+
END
|
12
|
+
end
|
13
|
+
|
14
|
+
if ARGV.size != 1
|
15
|
+
usage
|
16
|
+
Process.exit(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
if !File.exists?(MANIFEST_FILE)
|
20
|
+
puts "No Manifest file found in current directory."
|
21
|
+
Process.exit(2)
|
22
|
+
end
|
23
|
+
builder = Shipyard::Builder.new(MANIFEST_FILE, ARGV.first)
|
7
24
|
builder.generate
|
data/lib/shipyard/builder.rb
CHANGED
@@ -7,13 +7,20 @@ module Shipyard
|
|
7
7
|
attr_reader :table
|
8
8
|
attr_reader :db
|
9
9
|
|
10
|
-
def initialize(manifest_file)
|
11
|
-
@manifest = Manifest.new(manifest_file)
|
10
|
+
def initialize(manifest_file, table)
|
11
|
+
@manifest = Manifest.new(manifest_file, table)
|
12
12
|
@context = Context.new(@manifest)
|
13
13
|
end
|
14
14
|
|
15
15
|
def generate
|
16
|
-
Dir['*.erb']
|
16
|
+
templates = Dir['*.erb']
|
17
|
+
|
18
|
+
templates.each do |template|
|
19
|
+
abort "No destination mapped for template '#{template}'" unless !!@manifest.destination_for(template)
|
20
|
+
end
|
21
|
+
|
22
|
+
puts "Rendering to output directory #{@manifest.output_dir}"
|
23
|
+
templates.each do |filename|
|
17
24
|
open(filename) do |file|
|
18
25
|
# pass in the context object and render the template
|
19
26
|
template = ERB.new(file.read)
|
@@ -21,9 +28,13 @@ module Shipyard
|
|
21
28
|
code = template.result(@context.get_binding)
|
22
29
|
|
23
30
|
# write the rendered file to the associated destination
|
24
|
-
|
31
|
+
dst = @manifest.destination_for(filename)
|
32
|
+
output_file = File.join(@manifest.output_dir, dst)
|
25
33
|
File.makedirs(File.dirname(output_file))
|
26
|
-
open(output_file, 'w')
|
34
|
+
open(output_file, 'w') do |f|
|
35
|
+
puts "\t#{filename} => #{output_file}"
|
36
|
+
f.write(code)
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
29
40
|
end
|
data/lib/shipyard/context.rb
CHANGED
@@ -5,17 +5,17 @@ class Context
|
|
5
5
|
|
6
6
|
def initialize(manifest)
|
7
7
|
@db = manifest.database
|
8
|
-
@table = manifest.table
|
8
|
+
@table = manifest.table
|
9
|
+
@row = manifest.row
|
9
10
|
@dataset = @db[manifest.table]
|
10
|
-
@row = Inflector::singularize(manifest.table.to_s)
|
11
11
|
end
|
12
12
|
|
13
13
|
def columns
|
14
|
-
|
14
|
+
@db.schema(@table.to_sym).map { |arr| arr[0].to_s }
|
15
15
|
end
|
16
16
|
|
17
17
|
def columns_with_types
|
18
|
-
@db.schema(@table.to_sym).inject({}) { |r, v| r[v[0].to_s] = v[1][:type]
|
18
|
+
@db.schema(@table.to_sym).inject({}) { |r, v| r[v[0].to_s] = v[1][:type]; r }
|
19
19
|
end
|
20
20
|
|
21
21
|
def primary_key
|
data/lib/shipyard/manifest.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
1
3
|
module Shipyard
|
2
4
|
class Manifest
|
3
|
-
attr_reader :maps
|
5
|
+
attr_reader :table, :row, :maps
|
4
6
|
|
5
|
-
def initialize(filename)
|
7
|
+
def initialize(filename, table)
|
8
|
+
@table = table
|
9
|
+
@row = ActiveSupport::Inflector.singularize(table)
|
6
10
|
@maps = {}
|
7
11
|
open(filename) { |file| instance_eval(file.read) }
|
8
12
|
end
|
9
13
|
|
10
|
-
def table(name = nil)
|
11
|
-
@table = name if !!name
|
12
|
-
@table
|
13
|
-
end
|
14
|
-
|
15
14
|
def database(sequel = nil)
|
16
15
|
@database = sequel if !!sequel
|
17
16
|
@database
|
data/spec/context_spec.rb
CHANGED
@@ -6,18 +6,17 @@ module Shipyard
|
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
@test_dir = 'test_manifest'
|
9
|
+
@test_table = 'users'
|
9
10
|
Dir.mkdir(@test_dir)
|
10
11
|
@test_manifest = File.join(@test_dir, 'Manifest')
|
11
12
|
File.open(@test_manifest, 'w') do |file|
|
12
13
|
file.write <<-EOF
|
13
|
-
table :test_table
|
14
|
-
|
15
14
|
database Sequel.sqlite
|
16
15
|
|
17
16
|
map :test_template, 'controllers/test.rb'
|
18
17
|
EOF
|
19
18
|
end
|
20
|
-
@m = Manifest.new(@test_manifest)
|
19
|
+
@m = Manifest.new(@test_manifest, @test_table)
|
21
20
|
end
|
22
21
|
|
23
22
|
after(:each) do
|
@@ -28,27 +27,27 @@ module Shipyard
|
|
28
27
|
|
29
28
|
it "should read the table name from the manifest" do
|
30
29
|
ctx = Context.new(@m)
|
31
|
-
ctx.table.should ==
|
30
|
+
ctx.table.should == @test_table
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should have a method to return the columns of the table" do
|
35
34
|
ctx = Context.new(@m)
|
36
|
-
ctx.db.create_table
|
35
|
+
ctx.db.create_table @test_table.to_sym do
|
37
36
|
primary_key :id
|
38
37
|
String :name
|
39
38
|
end
|
40
|
-
ctx.columns.should == [
|
39
|
+
ctx.columns.should == ['id', 'name']
|
41
40
|
end
|
42
41
|
|
43
42
|
it "should have a method to return the columns with their types" do
|
44
43
|
ctx = Context.new(@m)
|
45
|
-
ctx.db.create_table
|
44
|
+
ctx.db.create_table @test_table.to_sym do
|
46
45
|
primary_key :id
|
47
46
|
column :name, :text
|
48
47
|
column :count, :integer
|
49
48
|
end
|
50
49
|
|
51
|
-
ctx.columns_with_types.should == {
|
50
|
+
ctx.columns_with_types.should == {'id' => :integer, 'name' => :string, 'count' => :integer}
|
52
51
|
end
|
53
52
|
|
54
53
|
end
|
data/spec/manifest_spec.rb
CHANGED
@@ -5,19 +5,18 @@ module Shipyard
|
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
@test_db = 'test.db'
|
8
|
+
@test_table = 'users'
|
8
9
|
@test_dir = 'test_manifest'
|
9
10
|
Dir.mkdir(@test_dir)
|
10
11
|
@test_manifest = File.join(@test_dir, 'Manifest')
|
11
12
|
File.open(@test_manifest, 'w') do |file|
|
12
13
|
file.write <<-EOF
|
13
|
-
table :test_table
|
14
|
-
|
15
14
|
database Sequel.sqlite
|
16
15
|
|
17
16
|
map :test_template, 'controllers/test.rb'
|
18
17
|
EOF
|
19
18
|
end
|
20
|
-
@m = Manifest.new(@test_manifest)
|
19
|
+
@m = Manifest.new(@test_manifest, @test_table)
|
21
20
|
end
|
22
21
|
|
23
22
|
after(:each) do
|
@@ -26,8 +25,8 @@ module Shipyard
|
|
26
25
|
@m = nil
|
27
26
|
end
|
28
27
|
|
29
|
-
it "should
|
30
|
-
@m.table.should ==
|
28
|
+
it "should take a table name in the constructor" do
|
29
|
+
@m.table.should == @test_table
|
31
30
|
end
|
32
31
|
|
33
32
|
it "should map template files to their output files" do
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shipyard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Chris Kite
|
@@ -9,29 +15,41 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-15 00:00:00 -05:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: activesupport
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 8
|
23
34
|
version: 2.3.8
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: sequel
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 55
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 12
|
49
|
+
- 0
|
33
50
|
version: 3.12.0
|
34
|
-
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
35
53
|
description:
|
36
54
|
email:
|
37
55
|
executables:
|
@@ -47,6 +65,9 @@ files:
|
|
47
65
|
- lib/shipyard/manifest.rb
|
48
66
|
- bin/shipyard
|
49
67
|
- README.rdoc
|
68
|
+
- spec/manifest_spec.rb
|
69
|
+
- spec/context_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
50
71
|
has_rdoc: true
|
51
72
|
homepage: http://www.github.com/chriskite/shipyard
|
52
73
|
licenses: []
|
@@ -60,21 +81,27 @@ rdoc_options:
|
|
60
81
|
require_paths:
|
61
82
|
- lib
|
62
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
63
85
|
requirements:
|
64
86
|
- - ">="
|
65
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
66
91
|
version: "0"
|
67
|
-
version:
|
68
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
69
94
|
requirements:
|
70
95
|
- - ">="
|
71
96
|
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
72
100
|
version: "0"
|
73
|
-
version:
|
74
101
|
requirements: []
|
75
102
|
|
76
103
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.3.
|
104
|
+
rubygems_version: 1.3.7
|
78
105
|
signing_key:
|
79
106
|
specification_version: 3
|
80
107
|
summary: Code generation tool for database-backed applications
|