conventional_models 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -4
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/conventional_models.gemspec +4 -1
- data/features/conventional_models.feature +1 -8
- data/features/output_model_code.feature +0 -3
- data/lib/conventional_models/conventions.rb +1 -6
- data/lib/conventional_models/database.rb +1 -2
- data/lib/conventional_models/table.rb +1 -2
- data/spec/conventional_models/conventions_spec.rb +1 -10
- data/spec/conventional_models/table_spec.rb +0 -11
- metadata +16 -2
data/README.rdoc
CHANGED
@@ -19,9 +19,6 @@ We have a table called Page and another called ContentItems (not following Activ
|
|
19
19
|
require 'conventional_models'
|
20
20
|
ConventionalModels.configure do
|
21
21
|
primary_key_name "Id"
|
22
|
-
table_name do |table|
|
23
|
-
table
|
24
|
-
end
|
25
22
|
end
|
26
23
|
|
27
24
|
# use the models
|
@@ -51,7 +48,7 @@ Output:
|
|
51
48
|
belongs_to_matcher {|column| column.name.end_with? "_id"}
|
52
49
|
belongs_to_name {|column| column.name.gsub(/_id$/, "")}
|
53
50
|
primary_key_name "id"
|
54
|
-
table_name {|
|
51
|
+
table_name {|name| name.pluralize}
|
55
52
|
class_name {|table_name| table_name.singularize.camelize}
|
56
53
|
ignore_tables "schema_migrations", "sqlite_sequence", "sysdiagrams"
|
57
54
|
end
|
data/Rakefile
CHANGED
@@ -15,6 +15,7 @@ begin
|
|
15
15
|
gem.add_development_dependency "rspec", ">= 1.3.0"
|
16
16
|
gem.add_development_dependency "cucumber", ">= 0.6.4"
|
17
17
|
gem.add_development_dependency "aruba", ">= 0.1.7"
|
18
|
+
gem.add_dependency "activerecord", ">= 2.3.5"
|
18
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
20
|
end
|
20
21
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/conventional_models.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{conventional_models}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steve Hodgkiss"]
|
@@ -66,15 +66,18 @@ Gem::Specification.new do |s|
|
|
66
66
|
s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
|
67
67
|
s.add_development_dependency(%q<cucumber>, [">= 0.6.4"])
|
68
68
|
s.add_development_dependency(%q<aruba>, [">= 0.1.7"])
|
69
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.5"])
|
69
70
|
else
|
70
71
|
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
71
72
|
s.add_dependency(%q<cucumber>, [">= 0.6.4"])
|
72
73
|
s.add_dependency(%q<aruba>, [">= 0.1.7"])
|
74
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
73
75
|
end
|
74
76
|
else
|
75
77
|
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
76
78
|
s.add_dependency(%q<cucumber>, [">= 0.6.4"])
|
77
79
|
s.add_dependency(%q<aruba>, [">= 0.1.7"])
|
80
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
78
81
|
end
|
79
82
|
end
|
80
83
|
|
@@ -32,11 +32,7 @@ Feature: ConventionalModels
|
|
32
32
|
require 'active_record'
|
33
33
|
ActiveRecord::Base.establish_connection(:database => '../test.sqlite', :adapter => 'sqlite3')
|
34
34
|
require 'conventional_models'
|
35
|
-
ConventionalModels.configure
|
36
|
-
table_name do |table|
|
37
|
-
table
|
38
|
-
end
|
39
|
-
end
|
35
|
+
ConventionalModels.configure
|
40
36
|
puts "Number of records: #{<model_name>.count}"
|
41
37
|
"""
|
42
38
|
When I run "ruby my_script.rb"
|
@@ -66,9 +62,6 @@ Feature: ConventionalModels
|
|
66
62
|
require 'conventional_models'
|
67
63
|
ConventionalModels.configure do
|
68
64
|
primary_key_name "Id"
|
69
|
-
table_name do |table|
|
70
|
-
table
|
71
|
-
end
|
72
65
|
end
|
73
66
|
page = Page.create :Name => 'test'
|
74
67
|
page.content_items.create :Name => 'content1'
|
@@ -22,9 +22,6 @@ Feature: Output model code
|
|
22
22
|
require 'conventional_models'
|
23
23
|
ConventionalModels.configure do
|
24
24
|
primary_key_name "Id"
|
25
|
-
table_name do |table|
|
26
|
-
table
|
27
|
-
end
|
28
25
|
end
|
29
26
|
puts "ContentItem code:<<\n#{ContentItem.model_code}>>"
|
30
27
|
puts "Page code:<<\n#{Page.model_code}>>"
|
@@ -6,7 +6,7 @@ module ConventionalModels
|
|
6
6
|
end
|
7
7
|
|
8
8
|
attr_accessor :ignored_tables, :primary_key_name, :class_name,
|
9
|
-
:
|
9
|
+
:belongs_to_matcher, :belongs_to_name
|
10
10
|
|
11
11
|
class Builder
|
12
12
|
def initialize(config)
|
@@ -14,7 +14,6 @@ module ConventionalModels
|
|
14
14
|
belongs_to_matcher {|column| column.name.end_with? "_id"}
|
15
15
|
belongs_to_name {|column| column.name.gsub(/_id$/, "")}
|
16
16
|
primary_key_name "id"
|
17
|
-
table_name {|table_name| table_name.pluralize}
|
18
17
|
class_name {|table_name| table_name.singularize.camelize}
|
19
18
|
ignore_tables "schema_migrations", "sqlite_sequence", "sysdiagrams"
|
20
19
|
end
|
@@ -27,10 +26,6 @@ module ConventionalModels
|
|
27
26
|
@config.primary_key_name = name
|
28
27
|
end
|
29
28
|
|
30
|
-
def table_name(&block)
|
31
|
-
@config.table_name = block
|
32
|
-
end
|
33
|
-
|
34
29
|
def belongs_to_matcher(&block)
|
35
30
|
@config.belongs_to_matcher = block
|
36
31
|
end
|
@@ -19,8 +19,7 @@ module ConventionalModels
|
|
19
19
|
@tables.each do |table|
|
20
20
|
table.belongs_to_names.each do |belongs_to|
|
21
21
|
name = conventions.belongs_to_name.call(belongs_to)
|
22
|
-
|
23
|
-
has_many_table = @tables.select{|t| t.name == table_name}.first
|
22
|
+
has_many_table = @tables.select{|t| t.class_name == conventions.class_name.call(name)}.first
|
24
23
|
if has_many_table
|
25
24
|
has_many_table.lines << "has_many :#{table.name.tableize}, :class_name => '#{table.class_name}', :primary_key => '#{conventions.primary_key_name}', :foreign_key => '#{belongs_to.name}'"
|
26
25
|
end
|
@@ -18,8 +18,7 @@ module ConventionalModels
|
|
18
18
|
|
19
19
|
@lines << "set_primary_key \"#{conventions.primary_key_name}\""
|
20
20
|
|
21
|
-
|
22
|
-
@lines << "set_table_name \"#{table_name}\""
|
21
|
+
@lines << "set_table_name \"#{@name}\""
|
23
22
|
|
24
23
|
@columns.each do |column|
|
25
24
|
if conventions.belongs_to_matcher.call(column)
|
@@ -16,15 +16,6 @@ module ConventionalModels
|
|
16
16
|
config.primary_key_name.should == "Id"
|
17
17
|
end
|
18
18
|
|
19
|
-
it "should set table name" do
|
20
|
-
config = Conventions.new do
|
21
|
-
table_name do |table_name|
|
22
|
-
table_name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
config.table_name.call("test").should == "test"
|
26
|
-
end
|
27
|
-
|
28
19
|
it "should set belongs to matcher" do
|
29
20
|
config = Conventions.new do
|
30
21
|
belongs_to_matcher do |column|
|
@@ -59,8 +50,8 @@ module ConventionalModels
|
|
59
50
|
config.belongs_to_name.call(@site_id_column).should == "site"
|
60
51
|
config.belongs_to_matcher.call(@site_id_column).should be_true
|
61
52
|
config.primary_key_name.should == "id"
|
62
|
-
config.table_name.call("pages").should == "pages"
|
63
53
|
config.class_name.call("pages").should == "Page"
|
54
|
+
config.class_name.call("page").should == "Page"
|
64
55
|
config.ignored_tables.should == %w{schema_migrations sqlite_sequence sysdiagrams}
|
65
56
|
end
|
66
57
|
end
|
@@ -36,17 +36,6 @@ module ConventionalModels
|
|
36
36
|
@table.lines[0].should == "set_primary_key \"ID\""
|
37
37
|
end
|
38
38
|
|
39
|
-
it "sets the table name" do
|
40
|
-
@conventions = Conventions.new do
|
41
|
-
table_name do |table|
|
42
|
-
"Test"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
@table = Table.new("Page", @columns)
|
46
|
-
@table.apply_conventions(@conventions)
|
47
|
-
@table.lines[1].should == "set_table_name \"Test\""
|
48
|
-
end
|
49
|
-
|
50
39
|
it "sets the class name" do
|
51
40
|
@conventions = Conventions.new do
|
52
41
|
class_name do |table|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Steve Hodgkiss
|
@@ -59,6 +59,20 @@ dependencies:
|
|
59
59
|
version: 0.1.7
|
60
60
|
prerelease: false
|
61
61
|
requirement: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activerecord
|
64
|
+
type: :runtime
|
65
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 2
|
71
|
+
- 3
|
72
|
+
- 5
|
73
|
+
version: 2.3.5
|
74
|
+
prerelease: false
|
75
|
+
requirement: *id004
|
62
76
|
description: Generate ActiveRecord models automatically with basic relationships based on conventions.
|
63
77
|
email: steve@hodgkiss.me.uk
|
64
78
|
executables: []
|