padrino-gen 0.10.5 → 0.10.6.a
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino-gen/generators/actions.rb +1 -1
- data/lib/padrino-gen/generators/components/actions.rb +4 -4
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +26 -19
- data/lib/padrino-gen/generators/components/orms/couchrest.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/mini_record.rb +131 -0
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/mongomatic.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/ohm.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/ripple.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/sequel.rb +6 -6
- data/lib/padrino-gen/generators/components/tests/bacon.rb +2 -2
- data/lib/padrino-gen/generators/components/tests/minitest.rb +2 -2
- data/lib/padrino-gen/generators/components/tests/riot.rb +2 -2
- data/lib/padrino-gen/generators/components/tests/rspec.rb +2 -2
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +2 -2
- data/lib/padrino-gen/generators/components/tests/testspec.rb +2 -2
- data/lib/padrino-gen/generators/mailer.rb +2 -2
- data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
- data/lib/padrino-gen/generators/project.rb +1 -1
- data/lib/padrino-gen/generators/runner.rb +4 -9
- data/lib/padrino-gen/generators/templates/initializer.rb.tt +1 -1
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +3 -0
- data/lib/padrino-gen.rb +1 -17
- data/padrino-gen.gemspec +0 -1
- data/test/fixtures/git_template.rb +1 -1
- data/test/test_migration_generator.rb +8 -8
- data/test/test_model_generator.rb +28 -1
- data/test/test_plugin_generator.rb +2 -1
- data/test/test_project_generator.rb +1 -1
- metadata +33 -20
@@ -306,7 +306,7 @@ module Padrino
|
|
306
306
|
# @api public
|
307
307
|
def initializer(name, data=nil)
|
308
308
|
@_init_name, @_init_data = name, data
|
309
|
-
register = data.present? ? " register #{name.to_s.camelize}Initializer\n" : " register #{name}\n"
|
309
|
+
register = data.present? ? " register #{name.to_s.underscore.camelize}Initializer\n" : " register #{name}\n"
|
310
310
|
inject_into_file destination_root("/app/app.rb"), register, :after => "Padrino::Application\n"
|
311
311
|
template "templates/initializer.rb.tt", destination_root("/lib/#{name}_init.rb") if data.present?
|
312
312
|
end
|
@@ -31,8 +31,8 @@ module Padrino
|
|
31
31
|
field_tuples.map! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
|
32
32
|
column_declarations = field_tuples.map(&options[:column_format]).join("\n ")
|
33
33
|
contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, options[:up]).gsub(/!DOWN!\n/m, options[:down])
|
34
|
-
contents = contents.gsub(/!NAME!/, model_name.camelize).gsub(/!TABLE!/, model_name.underscore)
|
35
|
-
contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.camelize)
|
34
|
+
contents = contents.gsub(/!NAME!/, model_name.underscore.camelize).gsub(/!TABLE!/, model_name.underscore)
|
35
|
+
contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize)
|
36
36
|
current_migration_number = return_last_migration_number
|
37
37
|
contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, (current_migration_number + 1).to_s)
|
38
38
|
migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
|
@@ -67,7 +67,7 @@ module Padrino
|
|
67
67
|
else
|
68
68
|
return if migration_exist?(filename)
|
69
69
|
change_format = options[:change_format]
|
70
|
-
migration_scan = filename.camelize.scan(/(Add|Remove)(?:.*?)(?:To|From)(.*?)$/).flatten
|
70
|
+
migration_scan = filename.underscore.camelize.scan(/(Add|Remove)(?:.*?)(?:To|From)(.*?)$/).flatten
|
71
71
|
direction, table_name = migration_scan[0].downcase, migration_scan[1].downcase.pluralize if migration_scan.any?
|
72
72
|
tuples = direction ? columns.map { |value| value.split(":") } : []
|
73
73
|
tuples.map! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
|
@@ -77,7 +77,7 @@ module Padrino
|
|
77
77
|
back_text = change_format.gsub(/!TABLE!/, table_name).gsub(/!COLUMNS!/, remove_columns) if tuples.any?
|
78
78
|
contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, (direction == 'add' ? forward_text.to_s : back_text.to_s))
|
79
79
|
contents.gsub!(/\s{4}!DOWN!\n/m, (direction == 'add' ? back_text.to_s : forward_text.to_s))
|
80
|
-
contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.camelize)
|
80
|
+
contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize)
|
81
81
|
current_migration_number = return_last_migration_number
|
82
82
|
contents.gsub!(/!VERSION!/, (current_migration_number + 1).to_s)
|
83
83
|
migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
|
@@ -29,8 +29,15 @@ ActiveRecord::Base.configurations[:test] = {
|
|
29
29
|
# Setup our logger
|
30
30
|
ActiveRecord::Base.logger = logger
|
31
31
|
|
32
|
+
# Raise exception on mass assignment protection for Active Record models
|
33
|
+
ActiveRecord::Base.mass_assignment_sanitizer = :strict
|
34
|
+
|
35
|
+
# Log the query plan for queries taking more than this (works
|
36
|
+
# with SQLite, MySQL, and PostgreSQL)
|
37
|
+
ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
|
38
|
+
|
32
39
|
# Include Active Record class name as root for JSON serialized output.
|
33
|
-
ActiveRecord::Base.include_root_in_json =
|
40
|
+
ActiveRecord::Base.include_root_in_json = false
|
34
41
|
|
35
42
|
# Store the full class name (including module namespace) in STI type column.
|
36
43
|
ActiveRecord::Base.store_full_sti_class = true
|
@@ -46,7 +53,7 @@ ActiveSupport.escape_html_entities_in_json = false
|
|
46
53
|
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
|
47
54
|
AR
|
48
55
|
|
49
|
-
MYSQL = (<<-MYSQL)
|
56
|
+
MYSQL = (<<-MYSQL) unless defined?(MYSQL)
|
50
57
|
:adapter => 'mysql',
|
51
58
|
:encoding => 'utf8',
|
52
59
|
:reconnect => true,
|
@@ -58,7 +65,7 @@ MYSQL = (<<-MYSQL)
|
|
58
65
|
:socket => '/tmp/mysql.sock'
|
59
66
|
MYSQL
|
60
67
|
|
61
|
-
MYSQL2 = (<<-MYSQL2)
|
68
|
+
MYSQL2 = (<<-MYSQL2) unless defined?(MYSQL2)
|
62
69
|
:adapter => 'mysql2',
|
63
70
|
:encoding => 'utf8',
|
64
71
|
:reconnect => true,
|
@@ -70,7 +77,7 @@ MYSQL2 = (<<-MYSQL2)
|
|
70
77
|
:socket => '/tmp/mysql.sock'
|
71
78
|
MYSQL2
|
72
79
|
|
73
|
-
POSTGRES = (<<-POSTGRES)
|
80
|
+
POSTGRES = (<<-POSTGRES) unless defined?(POSTGRES)
|
74
81
|
:adapter => 'postgresql',
|
75
82
|
:database => !DB_NAME!,
|
76
83
|
:username => 'root',
|
@@ -79,7 +86,7 @@ POSTGRES = (<<-POSTGRES)
|
|
79
86
|
:port => 5432
|
80
87
|
POSTGRES
|
81
88
|
|
82
|
-
SQLITE = (<<-SQLITE)
|
89
|
+
SQLITE = (<<-SQLITE) unless defined?(SQLITE)
|
83
90
|
:adapter => 'sqlite3',
|
84
91
|
:database => !DB_NAME!
|
85
92
|
SQLITE
|
@@ -90,24 +97,24 @@ def setup_orm
|
|
90
97
|
db = @app_name.underscore
|
91
98
|
case options[:adapter]
|
92
99
|
when 'mysql'
|
93
|
-
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"
|
94
|
-
ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"
|
95
|
-
ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"
|
100
|
+
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_development'")
|
101
|
+
ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_production'")
|
102
|
+
ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_test'")
|
96
103
|
require_dependencies 'mysql'
|
97
104
|
when 'mysql2'
|
98
|
-
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"
|
99
|
-
ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"
|
100
|
-
ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"
|
105
|
+
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_development'")
|
106
|
+
ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_production'")
|
107
|
+
ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_test'")
|
101
108
|
require_dependencies 'mysql2'
|
102
109
|
when 'postgres'
|
103
|
-
ar.gsub! /!DB_DEVELOPMENT!/, POSTGRES.gsub(/!DB_NAME!/,"
|
104
|
-
ar.gsub! /!DB_PRODUCTION!/, POSTGRES.gsub(/!DB_NAME!/,"
|
105
|
-
ar.gsub! /!DB_TEST!/, POSTGRES.gsub(/!DB_NAME!/,"
|
106
|
-
require_dependencies 'pg'
|
110
|
+
ar.gsub! /!DB_DEVELOPMENT!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_development'")
|
111
|
+
ar.gsub! /!DB_PRODUCTION!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_production'")
|
112
|
+
ar.gsub! /!DB_TEST!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_test'")
|
113
|
+
require_dependencies 'pg'
|
107
114
|
else
|
108
|
-
ar.gsub! /!DB_DEVELOPMENT!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db',
|
109
|
-
ar.gsub! /!DB_PRODUCTION!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db',
|
110
|
-
ar.gsub! /!DB_TEST!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db',
|
115
|
+
ar.gsub! /!DB_DEVELOPMENT!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_development.db')")
|
116
|
+
ar.gsub! /!DB_PRODUCTION!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_production.db')")
|
117
|
+
ar.gsub! /!DB_TEST!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_test.db')")
|
111
118
|
require_dependencies 'sqlite3'
|
112
119
|
end
|
113
120
|
require_dependencies 'activerecord', :require => 'active_record'
|
@@ -123,7 +130,7 @@ MODEL
|
|
123
130
|
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
124
131
|
def create_model_file(name, options={})
|
125
132
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
126
|
-
model_contents = AR_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
133
|
+
model_contents = AR_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
127
134
|
create_file(model_path, model_contents,:skip => true)
|
128
135
|
end
|
129
136
|
|
@@ -41,7 +41,7 @@ def create_model_file(name, options={})
|
|
41
41
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
42
42
|
field_tuples = options[:fields].map { |value| value.split(":") }
|
43
43
|
column_declarations = field_tuples.map { |field, kind| "property :#{field}" }.join("\n ")
|
44
|
-
model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
44
|
+
model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
45
45
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
46
46
|
create_file(model_path, model_contents)
|
47
47
|
end
|
@@ -66,10 +66,10 @@ MODEL
|
|
66
66
|
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
67
67
|
def create_model_file(name, options={})
|
68
68
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
69
|
-
model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
69
|
+
model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
70
70
|
field_tuples = options[:fields].map { |value| value.split(":") }
|
71
71
|
field_tuples.map! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
|
72
|
-
column_declarations = field_tuples.map { |field, kind|"property :#{field}, #{kind.camelize}" }.join("\n ")
|
72
|
+
column_declarations = field_tuples.map { |field, kind|"property :#{field}, #{kind.underscore.camelize}" }.join("\n ")
|
73
73
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
74
74
|
create_file(model_path, model_contents)
|
75
75
|
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
MR = (<<-MR) unless defined?(MR)
|
2
|
+
ActiveRecord::Base.configurations[:development] = {
|
3
|
+
!DB_DEVELOPMENT!
|
4
|
+
}
|
5
|
+
|
6
|
+
ActiveRecord::Base.configurations[:production] = {
|
7
|
+
!DB_PRODUCTION!
|
8
|
+
}
|
9
|
+
|
10
|
+
ActiveRecord::Base.configurations[:test] = {
|
11
|
+
!DB_TEST!
|
12
|
+
}
|
13
|
+
|
14
|
+
# Setup our logger
|
15
|
+
ActiveRecord::Base.logger = logger
|
16
|
+
|
17
|
+
# Raise exception on mass assignment protection for Active Record models
|
18
|
+
ActiveRecord::Base.mass_assignment_sanitizer = :strict
|
19
|
+
|
20
|
+
# Log the query plan for queries taking more than this (works
|
21
|
+
# with SQLite, MySQL, and PostgreSQL)
|
22
|
+
ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
|
23
|
+
|
24
|
+
# Doesn't include Active Record class name as root for JSON serialized output.
|
25
|
+
ActiveRecord::Base.include_root_in_json = false
|
26
|
+
|
27
|
+
# Store the full class name (including module namespace) in STI type column.
|
28
|
+
ActiveRecord::Base.store_full_sti_class = true
|
29
|
+
|
30
|
+
# Use ISO 8601 format for JSON serialized times and dates.
|
31
|
+
ActiveSupport.use_standard_json_time_format = true
|
32
|
+
|
33
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
34
|
+
# if you're including raw json in an HTML page.
|
35
|
+
ActiveSupport.escape_html_entities_in_json = false
|
36
|
+
|
37
|
+
# Now we can estabilish connection with our db
|
38
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
|
39
|
+
MR
|
40
|
+
|
41
|
+
MYSQL = (<<-MYSQL) unless defined?(MYSQL)
|
42
|
+
:adapter => 'mysql',
|
43
|
+
:encoding => 'utf8',
|
44
|
+
:reconnect => true,
|
45
|
+
:database => !DB_NAME!,
|
46
|
+
:pool => 5,
|
47
|
+
:username => 'root',
|
48
|
+
:password => '',
|
49
|
+
:host => 'localhost',
|
50
|
+
:socket => '/tmp/mysql.sock'
|
51
|
+
MYSQL
|
52
|
+
|
53
|
+
MYSQL2 = (<<-MYSQL2) unless defined?(MYSQL2)
|
54
|
+
:adapter => 'mysql2',
|
55
|
+
:encoding => 'utf8',
|
56
|
+
:reconnect => true,
|
57
|
+
:database => !DB_NAME!,
|
58
|
+
:pool => 5,
|
59
|
+
:username => 'root',
|
60
|
+
:password => '',
|
61
|
+
:host => 'localhost',
|
62
|
+
:socket => '/tmp/mysql.sock'
|
63
|
+
MYSQL2
|
64
|
+
|
65
|
+
POSTGRES = (<<-POSTGRES) unless defined?(POSTGRES)
|
66
|
+
:adapter => 'postgresql',
|
67
|
+
:database => !DB_NAME!,
|
68
|
+
:username => 'root',
|
69
|
+
:password => '',
|
70
|
+
:host => 'localhost',
|
71
|
+
:port => 5432
|
72
|
+
POSTGRES
|
73
|
+
|
74
|
+
SQLITE = (<<-SQLITE) unless defined?(SQLITE)
|
75
|
+
:adapter => 'sqlite3',
|
76
|
+
:database => !DB_NAME!
|
77
|
+
SQLITE
|
78
|
+
def setup_orm
|
79
|
+
ar = MR
|
80
|
+
db = @app_name.underscore
|
81
|
+
case options[:adapter]
|
82
|
+
when 'mysql'
|
83
|
+
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_development'")
|
84
|
+
ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_production'")
|
85
|
+
ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_test'")
|
86
|
+
require_dependencies 'mysql'
|
87
|
+
when 'mysql2'
|
88
|
+
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_development'")
|
89
|
+
ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_production'")
|
90
|
+
ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_test'")
|
91
|
+
require_dependencies 'mysql2'
|
92
|
+
when 'postgres'
|
93
|
+
ar.gsub! /!DB_DEVELOPMENT!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_development'")
|
94
|
+
ar.gsub! /!DB_PRODUCTION!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_production'")
|
95
|
+
ar.gsub! /!DB_TEST!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_test'")
|
96
|
+
require_dependencies 'pg'
|
97
|
+
else
|
98
|
+
ar.gsub! /!DB_DEVELOPMENT!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_development.db')")
|
99
|
+
ar.gsub! /!DB_PRODUCTION!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_production.db')")
|
100
|
+
ar.gsub! /!DB_TEST!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_test.db')")
|
101
|
+
require_dependencies 'sqlite3'
|
102
|
+
end
|
103
|
+
require_dependencies 'mini_record'
|
104
|
+
create_file('config/database.rb', ar)
|
105
|
+
insert_hook('ActiveRecord::Base.descendants.each(&:auto_upgrade!)', :after_load)
|
106
|
+
end
|
107
|
+
|
108
|
+
MR_MODEL = (<<-MODEL) unless defined?(MR_MODEL)
|
109
|
+
class !NAME! < ActiveRecord::Base
|
110
|
+
# Fields
|
111
|
+
!FIELDS!
|
112
|
+
end
|
113
|
+
MODEL
|
114
|
+
|
115
|
+
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
116
|
+
def create_model_file(name, options={})
|
117
|
+
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
118
|
+
field_tuples = options[:fields].map { |value| value.split(":") }
|
119
|
+
column_declarations = field_tuples.map { |field, kind| "field :#{field}, :as => :#{kind}" }.join("\n ")
|
120
|
+
model_contents = MR_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
121
|
+
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
122
|
+
create_file(model_path, model_contents)
|
123
|
+
end
|
124
|
+
|
125
|
+
def create_model_migration(migration_name, name, columns)
|
126
|
+
# NO MIGRATION NEEDED
|
127
|
+
end
|
128
|
+
|
129
|
+
def create_migration_file(migration_name, name, columns)
|
130
|
+
# NO MIGRATION NEEDED
|
131
|
+
end
|
@@ -53,8 +53,8 @@ MODEL
|
|
53
53
|
def create_model_file(name, options={})
|
54
54
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
55
55
|
field_tuples = options[:fields].map { |value| value.split(":") }
|
56
|
-
column_declarations = field_tuples.map { |field, kind| "field :#{field}, :type => #{kind.camelize}" }.join("\n ")
|
57
|
-
model_contents = MONGOID_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
56
|
+
column_declarations = field_tuples.map { |field, kind| "field :#{field}, :type => #{kind.underscore.camelize}" }.join("\n ")
|
57
|
+
model_contents = MONGOID_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
58
58
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
59
59
|
create_file(model_path, model_contents)
|
60
60
|
end
|
@@ -29,8 +29,8 @@ MODEL
|
|
29
29
|
def create_model_file(name, options={})
|
30
30
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
31
31
|
field_tuples = options[:fields].map { |value| value.split(":") }
|
32
|
-
column_declarations = field_tuples.map { |field, kind| "key :#{field}, #{kind.camelize}" }.join("\n ")
|
33
|
-
model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
32
|
+
column_declarations = field_tuples.map { |field, kind| "key :#{field}, #{kind.underscore.camelize}" }.join("\n ")
|
33
|
+
model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
34
34
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
35
35
|
create_file(model_path, model_contents)
|
36
36
|
end
|
@@ -69,7 +69,7 @@ def create_model_file(name, options={})
|
|
69
69
|
column_declarations = field_tuples.map { |field, kind| "be_present self['#{field}'], '#{field} cannot be blank'" }.join("\n ")
|
70
70
|
# Really ugly oneliner
|
71
71
|
integers = field_tuples.select { |col, type| type =~ /[Ii]nteger/ }.map { |field, kind| "be_a_number self['#{field}'], '#{field} must be a number'" }.join("\n ")
|
72
|
-
model_contents = MONGOMATIC_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
72
|
+
model_contents = MONGOMATIC_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
73
73
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
74
74
|
model_contents.gsub!(/!INTEGERS!/, integers)
|
75
75
|
create_file(model_path, model_contents)
|
@@ -56,8 +56,8 @@ MODEL
|
|
56
56
|
def create_model_file(name, options={})
|
57
57
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
58
58
|
field_tuples = options[:fields].map { |value| value.split(":") }
|
59
|
-
column_declarations = field_tuples.map { |field, kind| "attribute :#{field}, #{kind.camelize}" }.join("\n ")
|
60
|
-
model_contents = OHM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
59
|
+
column_declarations = field_tuples.map { |field, kind| "attribute :#{field}, #{kind.underscore.camelize}" }.join("\n ")
|
60
|
+
model_contents = OHM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
61
61
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
62
62
|
create_file(model_path, model_contents)
|
63
63
|
end
|
@@ -60,8 +60,8 @@ MODEL
|
|
60
60
|
def create_model_file(name, options={})
|
61
61
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
62
62
|
field_tuples = options[:fields].map { |value| value.split(":") }
|
63
|
-
column_declarations = field_tuples.map { |field, kind| "property :#{field}, #{kind.camelize}" }.join("\n ")
|
64
|
-
model_contents = RIPPLE_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
63
|
+
column_declarations = field_tuples.map { |field, kind| "property :#{field}, #{kind.underscore.camelize}" }.join("\n ")
|
64
|
+
model_contents = RIPPLE_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
65
65
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
66
66
|
create_file(model_path, model_contents)
|
67
67
|
end
|
@@ -42,17 +42,17 @@ MODEL
|
|
42
42
|
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
43
43
|
def create_model_file(name, options={})
|
44
44
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
45
|
-
model_contents = SQ_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
45
|
+
model_contents = SQ_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
46
46
|
create_file(model_path, model_contents)
|
47
47
|
end
|
48
48
|
|
49
49
|
SQ_MIGRATION = (<<-MIGRATION) unless defined?(SQ_MIGRATION)
|
50
|
-
|
51
|
-
|
50
|
+
Sequel.migration do
|
51
|
+
up do
|
52
52
|
!UP!
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
down do
|
56
56
|
!DOWN!
|
57
57
|
end
|
58
58
|
end
|
@@ -71,7 +71,7 @@ MIGRATION
|
|
71
71
|
|
72
72
|
def create_model_migration(migration_name, name, columns)
|
73
73
|
output_model_migration(migration_name, name, columns,
|
74
|
-
:column_format => Proc.new { |field, kind| "#{kind.camelize} :#{field}" },
|
74
|
+
:column_format => Proc.new { |field, kind| "#{kind.underscore.camelize} :#{field}" },
|
75
75
|
:base => SQ_MIGRATION, :up => SQ_MODEL_UP_MG, :down => SQ_MODEL_DOWN_MG)
|
76
76
|
end
|
77
77
|
|
@@ -84,7 +84,7 @@ MIGRATION
|
|
84
84
|
def create_migration_file(migration_name, name, columns)
|
85
85
|
output_migration_file(migration_name, name, columns,
|
86
86
|
:base => SQ_MIGRATION, :change_format => SQ_CHANGE_MG,
|
87
|
-
:add => Proc.new { |field, kind| "add_column :#{field}, #{kind.camelize}" },
|
87
|
+
:add => Proc.new { |field, kind| "add_column :#{field}, #{kind.underscore.camelize}" },
|
88
88
|
:remove => Proc.new { |field, kind| "drop_column :#{field}" }
|
89
89
|
)
|
90
90
|
end
|
@@ -62,13 +62,13 @@ end
|
|
62
62
|
|
63
63
|
# Generates a controller test given the controllers name
|
64
64
|
def generate_controller_test(name)
|
65
|
-
bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
65
|
+
bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
66
66
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
67
67
|
create_file destination_root(controller_test_path), bacon_contents, :skip => true
|
68
68
|
end
|
69
69
|
|
70
70
|
def generate_model_test(name)
|
71
|
-
bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
71
|
+
bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
72
72
|
path = options[:app] == '.' ? '/..' : '/../..'
|
73
73
|
bacon_contents.gsub!(/!PATH!/,path)
|
74
74
|
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
@@ -64,13 +64,13 @@ end
|
|
64
64
|
|
65
65
|
# Generates a controller test given the controllers name
|
66
66
|
def generate_controller_test(name)
|
67
|
-
minitest_contents = MINITEST_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
67
|
+
minitest_contents = MINITEST_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
68
68
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
69
69
|
create_file destination_root(controller_test_path), minitest_contents, :skip => true
|
70
70
|
end
|
71
71
|
|
72
72
|
def generate_model_test(name)
|
73
|
-
minitest_contents = MINITEST_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
73
|
+
minitest_contents = MINITEST_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
74
74
|
path = options[:app] == '.' ? '/..' : '/../..'
|
75
75
|
minitest_contents.gsub!(/!PATH!/,path)
|
76
76
|
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
@@ -88,13 +88,13 @@ end
|
|
88
88
|
|
89
89
|
# Generates a controller test given the controllers name
|
90
90
|
def generate_controller_test(name)
|
91
|
-
riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
91
|
+
riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
92
92
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
93
93
|
create_file destination_root(controller_test_path), riot_contents, :skip => true
|
94
94
|
end
|
95
95
|
|
96
96
|
def generate_model_test(name)
|
97
|
-
riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
97
|
+
riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
98
98
|
path = options[:app] == '.' ? '/..' : '/../..'
|
99
99
|
riot_contents.gsub!(/!PATH!/,path)
|
100
100
|
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
@@ -64,13 +64,13 @@ end
|
|
64
64
|
|
65
65
|
# Generates a controller test given the controllers name
|
66
66
|
def generate_controller_test(name)
|
67
|
-
rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
67
|
+
rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
68
68
|
controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
|
69
69
|
create_file destination_root(controller_spec_path), rspec_contents, :skip => true
|
70
70
|
end
|
71
71
|
|
72
72
|
def generate_model_test(name)
|
73
|
-
rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
73
|
+
rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
74
74
|
model_spec_path = File.join('spec',options[:app],'models',"#{name.to_s.underscore}_spec.rb")
|
75
75
|
create_file destination_root(model_spec_path), rspec_contents, :skip => true
|
76
76
|
end
|
@@ -71,13 +71,13 @@ end
|
|
71
71
|
|
72
72
|
# Generates a controller test given the controllers name
|
73
73
|
def generate_controller_test(name)
|
74
|
-
shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
74
|
+
shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
75
75
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
76
76
|
create_file destination_root(controller_test_path), shoulda_contents, :skip => true
|
77
77
|
end
|
78
78
|
|
79
79
|
def generate_model_test(name)
|
80
|
-
shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
80
|
+
shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
81
81
|
path = options[:app] == '.' ? '/..' : '/../..'
|
82
82
|
shoulda_contents.gsub!(/!PATH!/,path)
|
83
83
|
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
@@ -61,13 +61,13 @@ end
|
|
61
61
|
|
62
62
|
# Generates a controller test given the controllers name
|
63
63
|
def generate_controller_test(name)
|
64
|
-
testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
64
|
+
testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
65
65
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
66
66
|
create_file destination_root(controller_test_path), testspec_contents, :skip => true
|
67
67
|
end
|
68
68
|
|
69
69
|
def generate_model_test(name)
|
70
|
-
tests_contents = TESTSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
70
|
+
tests_contents = TESTSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
|
71
71
|
path = options[:app] == '.' ? '/..' : '/../..'
|
72
72
|
tests_contents.gsub!(/!PATH!/,path)
|
73
73
|
model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
|
@@ -40,9 +40,9 @@ module Padrino
|
|
40
40
|
self.behavior = :revoke if options[:destroy]
|
41
41
|
@app_name = fetch_app_name(app)
|
42
42
|
@actions = actions.map{|a| a.to_sym}
|
43
|
-
@short_name = name.to_s.gsub(/
|
43
|
+
@short_name = name.to_s.gsub(/_mailer/i, '').underscore.downcase
|
44
44
|
@mailer_basename = @short_name.underscore
|
45
|
-
template "templates/mailer.rb.tt", destination_root(app,
|
45
|
+
template "templates/mailer.rb.tt", destination_root(app, 'mailers', "#{@mailer_basename}.rb")
|
46
46
|
empty_directory destination_root(app, 'views', 'mailers', @mailer_basename)
|
47
47
|
else
|
48
48
|
say "You are not at the root of a Padrino application! (config/boot.rb not found)"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Defines our constants
|
2
|
-
PADRINO_ENV = ENV[
|
2
|
+
PADRINO_ENV = ENV['PADRINO_ENV'] ||= ENV['RACK_ENV'] ||= 'development' unless defined?(PADRINO_ENV)
|
3
3
|
PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT)
|
4
4
|
|
5
5
|
# Load our dependencies
|
@@ -11,7 +11,7 @@ Bundler.require(:default, PADRINO_ENV)
|
|
11
11
|
# Enable devel logging
|
12
12
|
#
|
13
13
|
# Padrino::Logger::Config[:development] = { :log_level => :devel, :stream => :stdout }
|
14
|
-
# Padrino::Logger
|
14
|
+
# Padrino::Logger::Config[:development][:log_static] = true
|
15
15
|
#
|
16
16
|
|
17
17
|
##
|
@@ -35,7 +35,7 @@ module Padrino
|
|
35
35
|
class_option :template, :desc => "Generate project from template", :aliases => '-p', :default => nil, :type => :string
|
36
36
|
|
37
37
|
# Definitions for the available customizable components
|
38
|
-
component_option :orm, "database engine", :aliases => '-d', :choices => [:activerecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic, :ripple], :default => :none
|
38
|
+
component_option :orm, "database engine", :aliases => '-d', :choices => [:activerecord, :mini_record, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic, :ripple], :default => :none
|
39
39
|
component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot, :minitest], :default => :none
|
40
40
|
component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr], :default => :none
|
41
41
|
component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools, :extcore, :dojo], :default => :none
|
@@ -93,16 +93,11 @@ module Padrino
|
|
93
93
|
# git :commit, "hello world"
|
94
94
|
#
|
95
95
|
# @api public
|
96
|
-
def git(
|
96
|
+
def git(*args)
|
97
97
|
FileUtils.cd(destination_root) do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
say "Git repo has been initialized", :green
|
102
|
-
else
|
103
|
-
@_git ||= ::Grit::Repo.new(destination_root)
|
104
|
-
@_git.method(action).call(arguments)
|
105
|
-
end
|
98
|
+
cmd = "git %s" % args.join(' ')
|
99
|
+
say cmd, :green
|
100
|
+
system cmd
|
106
101
|
end
|
107
102
|
end
|
108
103
|
|
@@ -304,6 +304,9 @@ if defined?(ActiveRecord)
|
|
304
304
|
# Get the model class
|
305
305
|
klass = m.camelize.constantize
|
306
306
|
|
307
|
+
# Avoid non ActiveRecord models
|
308
|
+
next unless klass.ancestors.include?(ActiveRecord::Base)
|
309
|
+
|
307
310
|
# Init the processing
|
308
311
|
print "Processing #{m.humanize}: "
|
309
312
|
FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
|
data/lib/padrino-gen.rb
CHANGED
@@ -1,25 +1,9 @@
|
|
1
1
|
require 'padrino-core/support_lite'
|
2
2
|
require 'padrino-core/tasks'
|
3
|
-
require 'padrino-
|
3
|
+
require 'padrino-gen/command'
|
4
4
|
require 'active_support/ordered_hash'
|
5
5
|
|
6
6
|
module Padrino
|
7
|
-
##
|
8
|
-
# This method return the correct location of padrino-gen bin or
|
9
|
-
# exec it using Kernel#system with the given args
|
10
|
-
#
|
11
|
-
# @param [Array<String>] args
|
12
|
-
# Splat of arguments to pass to padrino-gen
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")
|
16
|
-
#
|
17
|
-
# @api semipublic
|
18
|
-
def self.bin_gen(*args)
|
19
|
-
@_padrino_gen_bin ||= [Padrino.ruby_command, File.expand_path("../../bin/padrino-gen", __FILE__)]
|
20
|
-
args.empty? ? @_padrino_gen_bin : system(args.unshift(@_padrino_gen_bin).join(" "))
|
21
|
-
end
|
22
|
-
|
23
7
|
##
|
24
8
|
# This module it's used for register generators
|
25
9
|
#
|
data/padrino-gen.gemspec
CHANGED
@@ -50,9 +50,9 @@ describe "MigrationGenerator" do
|
|
50
50
|
capture_io { generate(:migration, 'add_email_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
|
51
51
|
capture_io { generate(:migration, 'add_name_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
|
52
52
|
capture_io { generate(:migration, 'add_age_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
|
53
|
-
assert_match_in_file(/
|
54
|
-
assert_match_in_file(/
|
55
|
-
assert_match_in_file(/
|
53
|
+
assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/001_add_email_to_person.rb")
|
54
|
+
assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/002_add_name_to_person.rb")
|
55
|
+
assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/003_add_age_to_user.rb")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -141,9 +141,9 @@ describe "MigrationGenerator" do
|
|
141
141
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
|
142
142
|
response_success = capture_io { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
|
143
143
|
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb"
|
144
|
-
assert_match_in_file(/
|
145
|
-
assert_match_in_file(/
|
146
|
-
assert_match_in_file(/
|
144
|
+
assert_match_in_file(/Sequel\.migration/m, migration_file_path)
|
145
|
+
assert_match_in_file(/up do\s+end/m, migration_file_path)
|
146
|
+
assert_match_in_file(/down do\s+end/m, migration_file_path)
|
147
147
|
end
|
148
148
|
|
149
149
|
should "generate migration for adding columns" do
|
@@ -151,7 +151,7 @@ describe "MigrationGenerator" do
|
|
151
151
|
migration_params = ['AddEmailToUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
152
152
|
response_success = capture_io { generate(:migration, *migration_params) }
|
153
153
|
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
|
154
|
-
assert_match_in_file(/
|
154
|
+
assert_match_in_file(/Sequel\.migration/m, migration_file_path)
|
155
155
|
assert_match_in_file(/alter_table :users.*?add_column :email, String/m, migration_file_path)
|
156
156
|
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
157
157
|
assert_match_in_file(/alter_table :users.*?drop_column :email/m, migration_file_path)
|
@@ -163,7 +163,7 @@ describe "MigrationGenerator" do
|
|
163
163
|
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
164
164
|
response_success = capture_io { generate(:migration, *migration_params) }
|
165
165
|
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb"
|
166
|
-
assert_match_in_file(/
|
166
|
+
assert_match_in_file(/Sequel\.migration/m, migration_file_path)
|
167
167
|
assert_match_in_file(/alter_table :users.*?drop_column :email/m, migration_file_path)
|
168
168
|
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
169
169
|
assert_match_in_file(/alter_table :users.*?add_column :email, String/m, migration_file_path)
|
@@ -117,6 +117,33 @@ describe "ModelGenerator" do
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
+
# MINIRECORD
|
121
|
+
context "model generator using mini_record" do
|
122
|
+
should "generate hooks for auto upgrade" do
|
123
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
|
124
|
+
assert_match_in_file(
|
125
|
+
"Padrino.after_load do\n ActiveRecord::Base.descendants.each(&:auto_upgrade!)",
|
126
|
+
"#{@apptmp}/sample_project/config/boot.rb"
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
should "generate model file" do
|
131
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
|
132
|
+
capture_io { generate(:model, 'user', 'name:string', 'surname:string', 'age:integer', "-r=#{@apptmp}/sample_project") }
|
133
|
+
assert_match_in_file(/class User < ActiveRecord::Base/m, "#{@apptmp}/sample_project/models/user.rb")
|
134
|
+
assert_match_in_file(/field :name, :as => :string/m, "#{@apptmp}/sample_project/models/user.rb")
|
135
|
+
assert_match_in_file(/field :surname, :as => :string/m, "#{@apptmp}/sample_project/models/user.rb")
|
136
|
+
assert_match_in_file(/field :age, :as => :integer/m, "#{@apptmp}/sample_project/models/user.rb")
|
137
|
+
end
|
138
|
+
|
139
|
+
should "generate model file with camelized name" do
|
140
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
|
141
|
+
capture_io { generate(:model, 'ChunkyBacon', "-r=#{@apptmp}/sample_project") }
|
142
|
+
assert_match_in_file(/class ChunkyBacon < ActiveRecord::Base/m, "#{@apptmp}/sample_project/models/chunky_bacon.rb")
|
143
|
+
assert_match_in_file(/ChunkyBacon Model/, "#{@apptmp}/sample_project/test/models/chunky_bacon_test.rb")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
120
147
|
# COUCHREST
|
121
148
|
context "model generator using couchrest" do
|
122
149
|
should "generate model file with no properties" do
|
@@ -210,7 +237,7 @@ describe "ModelGenerator" do
|
|
210
237
|
capture_io { generate(:model, 'person', "name:string", "age:integer", "created:datetime", "-r=#{@apptmp}/sample_project") }
|
211
238
|
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
|
212
239
|
assert_match_in_file(/class Person < Sequel::Model/m, "#{@apptmp}/sample_project/models/person.rb")
|
213
|
-
assert_match_in_file(/
|
240
|
+
assert_match_in_file(/Sequel\.migration do/m, migration_file_path)
|
214
241
|
assert_match_in_file(/create_table :people/m, migration_file_path)
|
215
242
|
assert_match_in_file(/String :name/m, migration_file_path)
|
216
243
|
assert_match_in_file(/Integer :age/m, migration_file_path)
|
@@ -84,12 +84,13 @@ describe "PluginGenerator" do
|
|
84
84
|
|
85
85
|
context "with git commands" do
|
86
86
|
should "generate a repository correctly" do
|
87
|
+
skip 'Change stubs here'
|
87
88
|
expects_generated_project :test => :rspec, :orm => :activerecord, :name => 'sample_git', :root => "#{@apptmp}"
|
88
89
|
expects_git :init, :root => "#{@apptmp}/sample_git"
|
89
90
|
expects_git :add, :arguments => '.', :root => "#{@apptmp}/sample_git"
|
90
91
|
expects_git :commit, :arguments => 'hello', :root => "#{@apptmp}/sample_git"
|
91
92
|
git_template_path = File.join(File.dirname(__FILE__), 'fixtures', 'git_template.rb')
|
92
|
-
capture_io { generate(:project, 'sample_git', "-p=#{git_template_path}", "-r=#{@apptmp}", '
|
93
|
+
capture_io { generate(:project, 'sample_git', "-p=#{git_template_path}", "-r=#{@apptmp}", '2>&1 /dev/null') }
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
@@ -240,7 +240,7 @@ describe "ProjectGenerator" do
|
|
240
240
|
|
241
241
|
should "properly generate postgres" do
|
242
242
|
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=activerecord', '--adapter=postgres') }
|
243
|
-
assert_match_in_file(/gem 'pg'
|
243
|
+
assert_match_in_file(/gem 'pg'$/, "#{@apptmp}/sample_project/Gemfile")
|
244
244
|
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
|
245
245
|
assert_match_in_file(%r{:adapter => 'postgresql'}, "#{@apptmp}/sample_project/config/database.rb")
|
246
246
|
end
|
metadata
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 98
|
5
|
+
prerelease: 7
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 10
|
9
|
+
- 6
|
10
|
+
- a
|
11
|
+
version: 0.10.6.a
|
6
12
|
platform: ruby
|
7
13
|
authors:
|
8
14
|
- Padrino Team
|
@@ -13,8 +19,7 @@ autorequire:
|
|
13
19
|
bindir: bin
|
14
20
|
cert_chain: []
|
15
21
|
|
16
|
-
date:
|
17
|
-
default_executable:
|
22
|
+
date: 2012-01-23 00:00:00 Z
|
18
23
|
dependencies:
|
19
24
|
- !ruby/object:Gem::Dependency
|
20
25
|
name: padrino-core
|
@@ -24,7 +29,13 @@ dependencies:
|
|
24
29
|
requirements:
|
25
30
|
- - "="
|
26
31
|
- !ruby/object:Gem::Version
|
27
|
-
|
32
|
+
hash: 98
|
33
|
+
segments:
|
34
|
+
- 0
|
35
|
+
- 10
|
36
|
+
- 6
|
37
|
+
- a
|
38
|
+
version: 0.10.6.a
|
28
39
|
type: :runtime
|
29
40
|
version_requirements: *id001
|
30
41
|
- !ruby/object:Gem::Dependency
|
@@ -35,20 +46,13 @@ dependencies:
|
|
35
46
|
requirements:
|
36
47
|
- - ~>
|
37
48
|
- !ruby/object:Gem::Version
|
49
|
+
hash: 15
|
50
|
+
segments:
|
51
|
+
- 1
|
52
|
+
- 0
|
38
53
|
version: "1.0"
|
39
54
|
type: :runtime
|
40
55
|
version_requirements: *id002
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: grit
|
43
|
-
prerelease: false
|
44
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
|
-
requirements:
|
47
|
-
- - ~>
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 2.4.1
|
50
|
-
type: :runtime
|
51
|
-
version_requirements: *id003
|
52
56
|
description: Generators for easily creating and building padrino applications from the console
|
53
57
|
email: padrinorb@gmail.com
|
54
58
|
executables:
|
@@ -77,6 +81,7 @@ files:
|
|
77
81
|
- lib/padrino-gen/generators/components/orms/activerecord.rb
|
78
82
|
- lib/padrino-gen/generators/components/orms/couchrest.rb
|
79
83
|
- lib/padrino-gen/generators/components/orms/datamapper.rb
|
84
|
+
- lib/padrino-gen/generators/components/orms/mini_record.rb
|
80
85
|
- lib/padrino-gen/generators/components/orms/mongoid.rb
|
81
86
|
- lib/padrino-gen/generators/components/orms/mongomapper.rb
|
82
87
|
- lib/padrino-gen/generators/components/orms/mongomatic.rb
|
@@ -159,7 +164,6 @@ files:
|
|
159
164
|
- lib/padrino-gen/generators/templates/static/ujs/mootools.js
|
160
165
|
- lib/padrino-gen/generators/templates/static/ujs/prototype.js
|
161
166
|
- lib/padrino-gen/generators/templates/static/ujs/right.js
|
162
|
-
has_rdoc: true
|
163
167
|
homepage: http://www.padrinorb.com
|
164
168
|
licenses: []
|
165
169
|
|
@@ -173,17 +177,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
177
|
requirements:
|
174
178
|
- - ">="
|
175
179
|
- !ruby/object:Gem::Version
|
180
|
+
hash: 3
|
181
|
+
segments:
|
182
|
+
- 0
|
176
183
|
version: "0"
|
177
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
185
|
none: false
|
179
186
|
requirements:
|
180
|
-
- - "
|
187
|
+
- - ">"
|
181
188
|
- !ruby/object:Gem::Version
|
182
|
-
|
189
|
+
hash: 25
|
190
|
+
segments:
|
191
|
+
- 1
|
192
|
+
- 3
|
193
|
+
- 1
|
194
|
+
version: 1.3.1
|
183
195
|
requirements: []
|
184
196
|
|
185
197
|
rubyforge_project: padrino-gen
|
186
|
-
rubygems_version: 1.
|
198
|
+
rubygems_version: 1.8.15
|
187
199
|
signing_key:
|
188
200
|
specification_version: 3
|
189
201
|
summary: Generators for easily creating and building padrino applications
|
@@ -203,3 +215,4 @@ test_files:
|
|
203
215
|
- test/test_model_generator.rb
|
204
216
|
- test/test_plugin_generator.rb
|
205
217
|
- test/test_project_generator.rb
|
218
|
+
has_rdoc:
|