padrino-gen 0.10.7 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/padrino-gen/generators/actions.rb +139 -102
- data/lib/padrino-gen/generators/app/app.rb.tt +55 -53
- data/lib/padrino-gen/generators/app.rb +16 -16
- data/lib/padrino-gen/generators/cli.rb +3 -3
- data/lib/padrino-gen/generators/components/actions.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +22 -18
- data/lib/padrino-gen/generators/components/orms/couchrest.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +2 -1
- data/lib/padrino-gen/generators/components/orms/{mini_record.rb → minirecord.rb} +9 -9
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +60 -6
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/mongomatic.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/ohm.rb +57 -10
- data/lib/padrino-gen/generators/components/orms/ripple.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/sequel.rb +15 -6
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
- data/lib/padrino-gen/generators/components/stylesheets/less.rb +1 -0
- data/lib/padrino-gen/generators/components/tests/bacon.rb +0 -2
- data/lib/padrino-gen/generators/components/tests/minitest.rb +0 -1
- data/lib/padrino-gen/generators/components/tests/riot.rb +0 -1
- data/lib/padrino-gen/generators/components/tests/rspec.rb +14 -15
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +0 -1
- data/lib/padrino-gen/generators/components/tests/testspec.rb +0 -1
- data/lib/padrino-gen/generators/controller.rb +14 -11
- data/lib/padrino-gen/generators/mailer.rb +14 -11
- data/lib/padrino-gen/generators/migration.rb +5 -5
- data/lib/padrino-gen/generators/model.rb +8 -7
- data/lib/padrino-gen/generators/plugin.rb +15 -9
- data/lib/padrino-gen/generators/project/.gitignore +2 -1
- data/lib/padrino-gen/generators/project/config/apps.rb.tt +10 -8
- data/lib/padrino-gen/generators/project/config.ru +0 -0
- data/lib/padrino-gen/generators/project/public/favicon.ico +0 -0
- data/lib/padrino-gen/generators/project.rb +53 -25
- data/lib/padrino-gen/generators/runner.rb +1 -1
- data/lib/padrino-gen/generators/templates/Gemfile.tt +8 -3
- data/lib/padrino-gen/generators/templates/Rakefile.tt +8 -0
- data/lib/padrino-gen/generators/templates/controller.rb.tt +8 -9
- data/lib/padrino-gen/generators/templates/gem/README.md.tt +29 -0
- data/lib/padrino-gen/generators/templates/gem/gemspec.tt +19 -0
- data/lib/padrino-gen/generators/templates/gem/lib/libname/version.tt +3 -0
- data/lib/padrino-gen/generators/templates/gem/lib/libname.tt +6 -0
- data/lib/padrino-gen/generators/templates/helper.rb.tt +1 -1
- data/lib/padrino-gen/generators/templates/mailer.rb.tt +1 -1
- data/lib/padrino-gen/generators/templates/static/js/dojo.js +238 -1
- data/lib/padrino-gen/generators/templates/static/js/ext.js +38 -1
- data/lib/padrino-gen/generators/templates/static/js/jquery.js +4 -4
- data/lib/padrino-gen/generators/templates/static/js/mootools.js +335 -276
- data/lib/padrino-gen/generators/templates/static/js/protopak.js +1 -1
- data/lib/padrino-gen/generators/templates/static/js/right.js +7 -1
- data/lib/padrino-gen/generators/templates/static/ujs/jquery.js +76 -75
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +8 -2
- data/lib/padrino-gen/padrino-tasks/database.rb +11 -0
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +38 -12
- data/lib/padrino-gen/padrino-tasks/minirecord.rb +19 -0
- data/lib/padrino-gen/padrino-tasks/mongoid.rb +76 -18
- data/lib/padrino-gen/padrino-tasks/mongomapper.rb +9 -1
- data/lib/padrino-gen/padrino-tasks/sequel.rb +6 -1
- data/lib/padrino-gen.rb +2 -2
- data/padrino-gen.gemspec +0 -0
- data/test/helper.rb +1 -1
- data/test/test_app_generator.rb +23 -4
- data/test/test_controller_generator.rb +8 -8
- data/test/test_mailer_generator.rb +5 -5
- data/test/test_model_generator.rb +26 -23
- data/test/test_plugin_generator.rb +23 -0
- data/test/test_project_generator.rb +82 -47
- metadata +17 -17
- data/lib/padrino-gen/padrino-tasks/seed.rb +0 -5
@@ -1,59 +1,61 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module <%= @project_name %>
|
2
|
+
class <%= @app_name %> < Padrino::Application
|
3
|
+
register Padrino::Rendering
|
4
|
+
register Padrino::Mailer
|
5
|
+
register Padrino::Helpers
|
5
6
|
|
6
|
-
|
7
|
+
enable :sessions
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
##
|
10
|
+
# Caching support
|
11
|
+
#
|
12
|
+
# register Padrino::Cache
|
13
|
+
# enable :caching
|
14
|
+
#
|
15
|
+
# You can customize caching store engines:
|
16
|
+
#
|
17
|
+
# set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
|
18
|
+
# set :cache, Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('127.0.0.1:11211', :exception_retry_limit => 1))
|
19
|
+
# set :cache, Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0))
|
20
|
+
# set :cache, Padrino::Cache::Store::Memory.new(50)
|
21
|
+
# set :cache, Padrino::Cache::Store::File.new(Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
|
22
|
+
#
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
##
|
25
|
+
# Application configuration options
|
26
|
+
#
|
27
|
+
# set :raise_errors, true # Raise exceptions (will stop application) (default for test)
|
28
|
+
# set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development)
|
29
|
+
# set :show_exceptions, true # Shows a stack trace in browser (default for development)
|
30
|
+
# set :logging, true # Logging in STDOUT for development and file for production (default only for development)
|
31
|
+
# set :public_folder, 'foo/bar' # Location for static assets (default root/public)
|
32
|
+
# set :reload, false # Reload application files (default in development)
|
33
|
+
# set :default_builder, 'foo' # Set a custom form builder (default 'StandardFormBuilder')
|
34
|
+
# set :locale_path, 'bar' # Set path for I18n translations (default your_app/locales)
|
35
|
+
# disable :sessions # Disabled sessions by default (enable if needed)
|
36
|
+
# disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined)
|
37
|
+
# layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
|
38
|
+
#
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
##
|
41
|
+
# You can configure for a specified environment like:
|
42
|
+
#
|
43
|
+
# configure :development do
|
44
|
+
# set :foo, :bar
|
45
|
+
# disable :asset_stamp # no asset timestamping for dev
|
46
|
+
# end
|
47
|
+
#
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
49
|
+
##
|
50
|
+
# You can manage errors like:
|
51
|
+
#
|
52
|
+
# error 404 do
|
53
|
+
# render 'errors/404'
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# error 505 do
|
57
|
+
# render 'errors/505'
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
end
|
59
61
|
end
|
@@ -19,12 +19,11 @@ module Padrino
|
|
19
19
|
include Padrino::Generators::Actions
|
20
20
|
|
21
21
|
desc "Description:\n\n\tpadrino-gen app generates a new Padrino application"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
class_option :
|
26
|
-
class_option :
|
27
|
-
class_option :tiny, :desc => "Generate tiny app skeleton", :aliases => '-i', :default => false, :type => :boolean
|
22
|
+
argument :name, :desc => 'The name of your padrino application'
|
23
|
+
class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
|
24
|
+
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
25
|
+
class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
|
26
|
+
class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
|
28
27
|
|
29
28
|
# Show help if no argv given
|
30
29
|
require_arguments!
|
@@ -34,24 +33,25 @@ module Padrino
|
|
34
33
|
# @api private
|
35
34
|
def create_app
|
36
35
|
self.destination_root = options[:root]
|
37
|
-
@
|
36
|
+
@app_folder = name.gsub(/\W/, '_').underscore
|
37
|
+
@app_name = name.gsub(/\W/, '_').underscore.camelize
|
38
38
|
if in_app_root?
|
39
|
+
@project_name = options[:namespace].underscore.camelize
|
40
|
+
@project_name = fetch_project_name(@app_folder) if @project_name.empty?
|
39
41
|
self.behavior = :revoke if options[:destroy]
|
40
|
-
app_skeleton(@
|
41
|
-
empty_directory destination_root("public/#{@
|
42
|
-
append_file destination_root(
|
42
|
+
app_skeleton(@app_folder.downcase, options[:tiny])
|
43
|
+
empty_directory destination_root("public/#{@app_folder.downcase}")
|
44
|
+
append_file destination_root('config/apps.rb'), "\nPadrino.mount('#{@project_name}::#{@app_name}', :app_file => Padrino.root('#{@app_folder.downcase}/app.rb')).to('/#{@app_folder.downcase}')"
|
43
45
|
|
44
46
|
return if self.behavior == :revoke
|
45
47
|
say
|
46
|
-
say
|
48
|
+
say '=' * 65, :green
|
47
49
|
say "Your #{@app_name} application has been installed."
|
48
|
-
say
|
50
|
+
say '='*65, :green
|
49
51
|
say "This application has been mounted to /#{@app_name.downcase}"
|
50
|
-
say "You can configure a different path by editing 'config/apps.rb"
|
51
|
-
say "="*65, :green
|
52
|
-
say
|
52
|
+
say "You can configure a different path by editing 'config/apps.rb'"
|
53
53
|
else
|
54
|
-
say
|
54
|
+
say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end # App
|
@@ -20,8 +20,8 @@ module Padrino
|
|
20
20
|
# @api private
|
21
21
|
def load_boot
|
22
22
|
begin
|
23
|
-
ENV['PADRINO_LOG_LEVEL'] ||=
|
24
|
-
ENV['BUNDLE_GEMFILE'] = File.join(options[:root],
|
23
|
+
ENV['PADRINO_LOG_LEVEL'] ||= 'test'
|
24
|
+
ENV['BUNDLE_GEMFILE'] = File.join(options[:root], 'Gemfile') if options[:root]
|
25
25
|
boot = options[:root] ? File.join(options[:root], 'config/boot.rb') : 'config/boot.rb'
|
26
26
|
if File.exist?(boot)
|
27
27
|
require File.expand_path(boot)
|
@@ -47,7 +47,7 @@ module Padrino
|
|
47
47
|
generator_class = Padrino::Generators.mappings[generator_kind]
|
48
48
|
|
49
49
|
if generator_class
|
50
|
-
args = ARGV.empty? && generator_class.require_arguments? ? [
|
50
|
+
args = ARGV.empty? && generator_class.require_arguments? ? ['-h'] : ARGV
|
51
51
|
generator_class.start(args)
|
52
52
|
else
|
53
53
|
puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(", ")})"
|
@@ -139,7 +139,7 @@ module Padrino
|
|
139
139
|
# @api private
|
140
140
|
def insert_test_suite_setup(suite_text, options={})
|
141
141
|
options.reverse_merge!(:path => "test/test_config.rb")
|
142
|
-
create_file(options[:path], suite_text.gsub(/CLASS_NAME/, @app_name))
|
142
|
+
create_file(options[:path], suite_text.gsub(/CLASS_NAME/, "#{@project_name}::#{@app_name}"))
|
143
143
|
end
|
144
144
|
|
145
145
|
# For mocking components
|
@@ -3,7 +3,7 @@ AR = (<<-AR) unless defined?(AR)
|
|
3
3
|
# You can use other adapters like:
|
4
4
|
#
|
5
5
|
# ActiveRecord::Base.configurations[:development] = {
|
6
|
-
# :adapter => '
|
6
|
+
# :adapter => 'mysql2',
|
7
7
|
# :encoding => 'utf8',
|
8
8
|
# :reconnect => true,
|
9
9
|
# :database => 'your_database',
|
@@ -29,11 +29,11 @@ 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
|
32
|
+
# Raise exception on mass assignment protection for Active Record models.
|
33
33
|
ActiveRecord::Base.mass_assignment_sanitizer = :strict
|
34
34
|
|
35
35
|
# Log the query plan for queries taking more than this (works
|
36
|
-
# with SQLite, MySQL, and PostgreSQL)
|
36
|
+
# with SQLite, MySQL, and PostgreSQL).
|
37
37
|
ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
|
38
38
|
|
39
39
|
# Include Active Record class name as root for JSON serialized output.
|
@@ -45,11 +45,11 @@ ActiveRecord::Base.store_full_sti_class = true
|
|
45
45
|
# Use ISO 8601 format for JSON serialized times and dates.
|
46
46
|
ActiveSupport.use_standard_json_time_format = true
|
47
47
|
|
48
|
-
# Don't escape HTML entities in JSON, leave that for the #json_escape helper
|
49
|
-
# if you're including raw
|
48
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper
|
49
|
+
# if you're including raw JSON in an HTML page.
|
50
50
|
ActiveSupport.escape_html_entities_in_json = false
|
51
51
|
|
52
|
-
# Now we can
|
52
|
+
# Now we can establish connection with our db.
|
53
53
|
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
|
54
54
|
AR
|
55
55
|
|
@@ -94,14 +94,15 @@ SQLITE
|
|
94
94
|
|
95
95
|
def setup_orm
|
96
96
|
ar = AR
|
97
|
-
db = @
|
97
|
+
db = @project_name.underscore
|
98
|
+
# We're now defaulting to mysql2 since mysql is deprecated
|
98
99
|
case options[:adapter]
|
99
|
-
when 'mysql'
|
100
|
+
when 'mysql-gem'
|
100
101
|
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_development'")
|
101
102
|
ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_production'")
|
102
103
|
ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_test'")
|
103
|
-
require_dependencies 'mysql'
|
104
|
-
when 'mysql2'
|
104
|
+
require_dependencies 'mysql', :version => "~> 2.8.1"
|
105
|
+
when 'mysql', 'mysql2'
|
105
106
|
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_development'")
|
106
107
|
ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_production'")
|
107
108
|
ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_test'")
|
@@ -117,7 +118,7 @@ def setup_orm
|
|
117
118
|
ar.gsub! /!DB_TEST!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_test.db')")
|
118
119
|
require_dependencies 'sqlite3'
|
119
120
|
end
|
120
|
-
require_dependencies 'activerecord', :require => 'active_record'
|
121
|
+
require_dependencies 'activerecord', :require => 'active_record', :version => ">= 3.1"
|
121
122
|
insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement'
|
122
123
|
create_file("config/database.rb", ar)
|
123
124
|
end
|
@@ -148,7 +149,7 @@ class !FILECLASS! < ActiveRecord::Migration
|
|
148
149
|
end
|
149
150
|
MIGRATION
|
150
151
|
|
151
|
-
AR_MODEL_UP_MG = (<<-MIGRATION)
|
152
|
+
AR_MODEL_UP_MG = (<<-MIGRATION) unless defined?(AR_MODEL_UP_MG)
|
152
153
|
create_table :!TABLE! do |t|
|
153
154
|
!FIELDS!
|
154
155
|
t.timestamps
|
@@ -161,9 +162,11 @@ MIGRATION
|
|
161
162
|
|
162
163
|
def create_model_migration(migration_name, name, columns)
|
163
164
|
output_model_migration(migration_name, name, columns,
|
164
|
-
|
165
|
-
|
166
|
-
|
165
|
+
:base => AR_MIGRATION,
|
166
|
+
:column_format => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
|
167
|
+
:up => AR_MODEL_UP_MG,
|
168
|
+
:down => AR_MODEL_DOWN_MG
|
169
|
+
)
|
167
170
|
end
|
168
171
|
|
169
172
|
AR_CHANGE_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(AR_CHANGE_MG)
|
@@ -174,8 +177,9 @@ MIGRATION
|
|
174
177
|
|
175
178
|
def create_migration_file(migration_name, name, columns)
|
176
179
|
output_migration_file(migration_name, name, columns,
|
177
|
-
:base
|
178
|
-
:
|
179
|
-
:
|
180
|
+
:base => AR_MIGRATION,
|
181
|
+
:change_format => AR_CHANGE_MG,
|
182
|
+
:add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
|
183
|
+
:remove => Proc.new { |field, kind| "t.remove :#{field}" }
|
180
184
|
)
|
181
185
|
end
|
@@ -25,7 +25,7 @@ COUCHREST
|
|
25
25
|
def setup_orm
|
26
26
|
require_dependencies 'couchrest_model', :version => '~>1.1.0'
|
27
27
|
require_dependencies 'json_pure'
|
28
|
-
create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, @
|
28
|
+
create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, @project_name.underscore))
|
29
29
|
end
|
30
30
|
|
31
31
|
CR_MODEL = (<<-MODEL) unless defined?(CR_MODEL)
|
@@ -14,11 +14,11 @@ ActiveRecord::Base.configurations[:test] = {
|
|
14
14
|
# Setup our logger
|
15
15
|
ActiveRecord::Base.logger = logger
|
16
16
|
|
17
|
-
# Raise exception on mass assignment protection for Active Record models
|
17
|
+
# Raise exception on mass assignment protection for Active Record models.
|
18
18
|
ActiveRecord::Base.mass_assignment_sanitizer = :strict
|
19
19
|
|
20
20
|
# Log the query plan for queries taking more than this (works
|
21
|
-
# with SQLite, MySQL, and PostgreSQL)
|
21
|
+
# with SQLite, MySQL, and PostgreSQL).
|
22
22
|
ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
|
23
23
|
|
24
24
|
# Doesn't include Active Record class name as root for JSON serialized output.
|
@@ -30,11 +30,11 @@ ActiveRecord::Base.store_full_sti_class = true
|
|
30
30
|
# Use ISO 8601 format for JSON serialized times and dates.
|
31
31
|
ActiveSupport.use_standard_json_time_format = true
|
32
32
|
|
33
|
-
# Don't escape HTML entities in JSON, leave that for the #json_escape helper
|
34
|
-
# if you're including raw
|
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
35
|
ActiveSupport.escape_html_entities_in_json = false
|
36
36
|
|
37
|
-
# Now we can
|
37
|
+
# Now we can establish connection with our db.
|
38
38
|
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
|
39
39
|
MR
|
40
40
|
|
@@ -77,14 +77,14 @@ SQLITE = (<<-SQLITE) unless defined?(SQLITE)
|
|
77
77
|
SQLITE
|
78
78
|
def setup_orm
|
79
79
|
ar = MR
|
80
|
-
db = @
|
80
|
+
db = @project_name.underscore
|
81
81
|
case options[:adapter]
|
82
|
-
when 'mysql'
|
82
|
+
when 'mysql-gem'
|
83
83
|
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_development'")
|
84
84
|
ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_production'")
|
85
85
|
ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_test'")
|
86
|
-
require_dependencies 'mysql'
|
87
|
-
when 'mysql2'
|
86
|
+
require_dependencies 'mysql', :version => "~> 2.8.1"
|
87
|
+
when 'mysql', 'mysql2'
|
88
88
|
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_development'")
|
89
89
|
ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_production'")
|
90
90
|
ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_test'")
|
@@ -1,5 +1,4 @@
|
|
1
1
|
MONGOID = (<<-MONGO) unless defined?(MONGOID)
|
2
|
-
|
3
2
|
# Connection.new takes host, port
|
4
3
|
host = 'localhost'
|
5
4
|
port = Mongo::Connection::DEFAULT_PORT
|
@@ -23,14 +22,69 @@ Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
|
|
23
22
|
# ]
|
24
23
|
# end
|
25
24
|
#
|
26
|
-
# More installation and setup notes are on http://mongoid.org/
|
25
|
+
# More installation and setup notes are on http://mongoid.org/
|
26
|
+
MONGO
|
27
|
+
|
28
|
+
MONGOID3 = (<<-MONGO) unless defined?(MONGOID3)
|
29
|
+
# Connection.new takes host, port
|
30
|
+
|
31
|
+
host = 'localhost'
|
32
|
+
port = 27017
|
33
|
+
|
34
|
+
database_name = case Padrino.env
|
35
|
+
when :development then '!NAME!_development'
|
36
|
+
when :production then '!NAME!_production'
|
37
|
+
when :test then '!NAME!_test'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Use MONGO_URI if it's set as an environmental variable
|
41
|
+
Mongoid::Config.sessions =
|
42
|
+
if ENV['MONGO_URI']
|
43
|
+
{default: {uri: ENV['MONGO_URI'] }}
|
44
|
+
else
|
45
|
+
{default: {hosts: ["#\{host\}:#\{port\}"], database: database_name}}
|
46
|
+
end
|
47
|
+
|
48
|
+
# If you want to use a YML file for config, use this instead:
|
49
|
+
#
|
50
|
+
# Mongoid.load!(File.join(Padrino.root, 'config', 'database.yml'), Padrino.env)
|
51
|
+
#
|
52
|
+
# And add a config/database.yml file like this:
|
53
|
+
# development:
|
54
|
+
# sessions:
|
55
|
+
# default:
|
56
|
+
# database: !NAME!_development
|
57
|
+
# hosts:
|
58
|
+
# - localhost:27017
|
59
|
+
# production:
|
60
|
+
# sessions:
|
61
|
+
# default:
|
62
|
+
# database: !NAME!_production
|
63
|
+
# hosts:
|
64
|
+
# - localhost:27017
|
65
|
+
# test:
|
66
|
+
# sessions:
|
67
|
+
# default:
|
68
|
+
# database: !NAME!_test
|
69
|
+
# hosts:
|
70
|
+
# - localhost:27017
|
71
|
+
#
|
72
|
+
#
|
73
|
+
# More installation and setup notes are on http://mongoid.org/en/mongoid/docs/installation.html#configuration
|
27
74
|
MONGO
|
28
75
|
|
29
76
|
def setup_orm
|
30
|
-
require_dependencies '
|
31
|
-
|
32
|
-
|
33
|
-
|
77
|
+
require_dependencies 'mongoid', :version => (RUBY_VERSION >= '1.9' ? '~>3.0.0' : '~>2.0')
|
78
|
+
|
79
|
+
if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
|
80
|
+
require_dependencies('SystemTimer', :require => 'system_timer')
|
81
|
+
end
|
82
|
+
|
83
|
+
if RUBY_VERSION >= '1.9'
|
84
|
+
create_file('config/database.rb', MONGOID3.gsub(/!NAME!/, @project_name.underscore))
|
85
|
+
else
|
86
|
+
create_file('config/database.rb', MONGOID.gsub(/!NAME!/, @project_name.underscore))
|
87
|
+
end
|
34
88
|
end
|
35
89
|
|
36
90
|
MONGOID_MODEL = (<<-MODEL) unless defined?(MONGOID_MODEL)
|
@@ -9,10 +9,10 @@ end
|
|
9
9
|
MONGO
|
10
10
|
|
11
11
|
def setup_orm
|
12
|
-
require_dependencies 'bson_ext', :require => 'mongo'
|
13
12
|
require_dependencies 'mongo_mapper'
|
13
|
+
require_dependencies 'bson_ext', :require => 'mongo'
|
14
14
|
require_dependencies('SystemTimer', :require => 'system_timer') if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
|
15
|
-
create_file("config/database.rb", MONGO.gsub(/!NAME!/, @
|
15
|
+
create_file("config/database.rb", MONGO.gsub(/!NAME!/, @project_name.underscore))
|
16
16
|
end
|
17
17
|
|
18
18
|
MM_MODEL = (<<-MODEL) unless defined?(MM_MODEL)
|
@@ -9,9 +9,9 @@ MONGO
|
|
9
9
|
|
10
10
|
def setup_orm
|
11
11
|
mongomatic = MONGOMATIC
|
12
|
-
require_dependencies 'bson_ext', :require => 'mongo'
|
13
12
|
require_dependencies 'mongomatic'
|
14
|
-
|
13
|
+
require_dependencies 'bson_ext', :require => 'mongo'
|
14
|
+
create_file("config/database.rb", MONGOMATIC.gsub(/!NAME!/, @project_name.underscore))
|
15
15
|
end
|
16
16
|
|
17
17
|
MONGOMATIC_MODEL = (<<-MODEL) unless defined?(MONGOMATIC_MODEL)
|
@@ -20,24 +20,71 @@ OHM = (<<-OHM) unless defined?(OHM)
|
|
20
20
|
# when :production then Ohm.connect(:db => 1)
|
21
21
|
# when :test then Ohm.connect(:db => 2)
|
22
22
|
# end
|
23
|
+
|
24
|
+
# This monkey patch provides traditional (hash of arrays) error handling for ohm models
|
25
|
+
# Also add compatiblity with admin generator.
|
26
|
+
module Ohm
|
27
|
+
class Model
|
28
|
+
|
29
|
+
alias_method :old_errors, :errors
|
30
|
+
def errors
|
31
|
+
@errors ||= ErrorsHash.new(self.class.to_reference, self.old_errors)
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_attributes(attrs)
|
35
|
+
attrs.each do |key, value|
|
36
|
+
send(:"\#{key}=", value)
|
37
|
+
end if attrs
|
38
|
+
end
|
39
|
+
|
40
|
+
class << self
|
41
|
+
alias_method :old_attribute, :attribute
|
42
|
+
def attribute(name, cast=nil)
|
43
|
+
attributes << name
|
44
|
+
old_attribute(name, cast)
|
45
|
+
end
|
46
|
+
|
47
|
+
def attributes
|
48
|
+
@_attributes ||= []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ErrorsHash < Hash
|
53
|
+
def initialize(scope, errors)
|
54
|
+
@scope = scope
|
55
|
+
self.replace Hash.new { |hash, key| hash[key] = [] }
|
56
|
+
|
57
|
+
errors.each do |key, value|
|
58
|
+
self[key] << value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def push(arr)
|
63
|
+
self[arr[0]] << arr[1]
|
64
|
+
end
|
65
|
+
|
66
|
+
def full_messages
|
67
|
+
self.map do |key, value|
|
68
|
+
value.uniq.map do |reason|
|
69
|
+
I18n::t("ohm.%s.%s.%s" % [@scope, key, reason])
|
70
|
+
end.join(', ')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end # unless Ohm::Model.new.errors.is_a?(Hash)
|
23
76
|
OHM
|
24
77
|
|
25
78
|
def setup_orm
|
26
|
-
ohm
|
27
|
-
|
28
|
-
require_dependencies 'ohm', :require => 'ohm'
|
29
|
-
require_dependencies 'ohm-contrib', :require => 'ohm/contrib'
|
30
|
-
create_file("config/database.rb", ohm)
|
79
|
+
require_dependencies 'ohm'
|
80
|
+
create_file("config/database.rb", OHM)
|
31
81
|
end
|
32
82
|
|
33
83
|
OHM_MODEL = (<<-MODEL) unless defined?(OHM_MODEL)
|
34
84
|
class !NAME! < Ohm::Model
|
35
|
-
include Ohm::Timestamping
|
36
|
-
include Ohm::Typecast
|
37
|
-
|
38
85
|
# Examples:
|
39
86
|
# attribute :name
|
40
|
-
# attribute :email
|
87
|
+
# attribute :email
|
41
88
|
# reference :venue, Venue
|
42
89
|
# set :participants, Person
|
43
90
|
# counter :votes
|
@@ -56,7 +103,7 @@ MODEL
|
|
56
103
|
def create_model_file(name, options={})
|
57
104
|
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
58
105
|
field_tuples = options[:fields].map { |value| value.split(":") }
|
59
|
-
column_declarations = field_tuples.map { |field, kind| "attribute :#{field}
|
106
|
+
column_declarations = field_tuples.map { |field, kind| "attribute :#{field}" }.join("\n ")
|
60
107
|
model_contents = OHM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
61
108
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
62
109
|
create_file(model_path, model_contents)
|
@@ -35,7 +35,7 @@ RIAK
|
|
35
35
|
|
36
36
|
def setup_orm
|
37
37
|
require_dependencies 'ripple'
|
38
|
-
create_file("config/riak.yml", RIPPLE_DB.gsub(/!NAME!/, @
|
38
|
+
create_file("config/riak.yml", RIPPLE_DB.gsub(/!NAME!/, @project_name.underscore))
|
39
39
|
create_file("config/database.rb", RIPPLE_CFG)
|
40
40
|
end
|
41
41
|
|
@@ -10,23 +10,32 @@ SEQUEL
|
|
10
10
|
|
11
11
|
def setup_orm
|
12
12
|
sequel = SEQUEL
|
13
|
-
db = @
|
13
|
+
db = @project_name.underscore
|
14
14
|
require_dependencies 'sequel'
|
15
|
-
|
15
|
+
case options[:adapter]
|
16
|
+
when 'mysql-gem'
|
17
|
+
sequel.gsub!(/!DB_DEVELOPMENT!/, "\"mysql://localhost/#{db}_development\"")
|
18
|
+
sequel.gsub!(/!DB_PRODUCTION!/, "\"mysql://localhost/#{db}_production\"")
|
19
|
+
sequel.gsub!(/!DB_TEST!/,"\"mysql://localhost/#{db}_test\"")
|
20
|
+
require_dependencies 'mysql', :version => "~> 2.8.1"
|
21
|
+
'mysql'
|
16
22
|
when 'mysql', 'mysql2'
|
17
|
-
sequel.gsub!(/!DB_DEVELOPMENT!/, "\"
|
18
|
-
sequel.gsub!(/!DB_PRODUCTION!/, "\"
|
19
|
-
sequel.gsub!(/!DB_TEST!/,"\"
|
20
|
-
|
23
|
+
sequel.gsub!(/!DB_DEVELOPMENT!/, "\"mysql2://localhost/#{db}_development\"")
|
24
|
+
sequel.gsub!(/!DB_PRODUCTION!/, "\"mysql2://localhost/#{db}_production\"")
|
25
|
+
sequel.gsub!(/!DB_TEST!/,"\"mysql2://localhost/#{db}_test\"")
|
26
|
+
require_dependencies 'mysql2'
|
27
|
+
'mysql2'
|
21
28
|
when 'postgres'
|
22
29
|
sequel.gsub!(/!DB_DEVELOPMENT!/, "\"postgres://localhost/#{db}_development\"")
|
23
30
|
sequel.gsub!(/!DB_PRODUCTION!/, "\"postgres://localhost/#{db}_production\"")
|
24
31
|
sequel.gsub!(/!DB_TEST!/,"\"postgres://localhost/#{db}_test\"")
|
32
|
+
require_dependencies 'pg'
|
25
33
|
'pg'
|
26
34
|
else
|
27
35
|
sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_development.db\")")
|
28
36
|
sequel.gsub!(/!DB_PRODUCTION!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_production.db\")")
|
29
37
|
sequel.gsub!(/!DB_TEST!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_test.db\")")
|
38
|
+
require_dependencies 'sqlite3'
|
30
39
|
'sqlite3'
|
31
40
|
end
|
32
41
|
create_file("config/database.rb", sequel)
|