padrino-gen 0.6.3 → 0.6.7

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.
Files changed (37) hide show
  1. data/Rakefile +1 -1
  2. data/VERSION +1 -1
  3. data/bin/padrino-gen +2 -2
  4. data/lib/padrino-gen/generators/actions.rb +50 -30
  5. data/lib/padrino-gen/generators/app/Gemfile +1 -0
  6. data/lib/padrino-gen/generators/app/config/boot.rb +1 -1
  7. data/lib/padrino-gen/generators/app.rb +7 -6
  8. data/lib/padrino-gen/generators/components/actions.rb +55 -56
  9. data/lib/padrino-gen/generators/components/orms/activerecord_gen.rb +48 -31
  10. data/lib/padrino-gen/generators/components/orms/couchrest_gen.rb +7 -9
  11. data/lib/padrino-gen/generators/components/orms/datamapper_gen.rb +16 -12
  12. data/lib/padrino-gen/generators/components/orms/mongomapper_gen.rb +6 -20
  13. data/lib/padrino-gen/generators/components/orms/sequel_gen.rb +6 -9
  14. data/lib/padrino-gen/generators/components/renderers/haml_gen.rb +1 -2
  15. data/lib/padrino-gen/generators/components/scripts/jquery_gen.rb +2 -2
  16. data/lib/padrino-gen/generators/components/scripts/prototype_gen.rb +3 -3
  17. data/lib/padrino-gen/generators/components/scripts/rightjs_gen.rb +2 -4
  18. data/lib/padrino-gen/generators/components/tests/bacon_test_gen.rb +3 -3
  19. data/lib/padrino-gen/generators/components/tests/riot_test_gen.rb +3 -3
  20. data/lib/padrino-gen/generators/components/tests/rspec_test_gen.rb +3 -3
  21. data/lib/padrino-gen/generators/components/tests/shoulda_test_gen.rb +3 -3
  22. data/lib/padrino-gen/generators/components/tests/testspec_test_gen.rb +3 -3
  23. data/lib/padrino-gen/generators/controller.rb +9 -8
  24. data/lib/padrino-gen/generators/mailer.rb +6 -5
  25. data/lib/padrino-gen/generators/migration.rb +5 -5
  26. data/lib/padrino-gen/generators/model.rb +5 -5
  27. data/lib/padrino-gen/generators.rb +12 -8
  28. data/lib/padrino-gen/padrino-tasks/activerecord.rb +33 -32
  29. data/lib/padrino-gen.rb +3 -0
  30. data/padrino-gen.gemspec +5 -5
  31. data/test/helper.rb +1 -1
  32. data/test/test_app_generator.rb +38 -39
  33. data/test/test_controller_generator.rb +11 -11
  34. data/test/test_mailer_generator.rb +4 -4
  35. data/test/test_migration_generator.rb +21 -21
  36. data/test/test_model_generator.rb +29 -31
  37. metadata +3 -3
@@ -6,13 +6,11 @@ module Padrino
6
6
  module SequelGen
7
7
 
8
8
  SEQUEL = (<<-SEQUEL).gsub(/^ {10}/, '')
9
- module DatabaseSetup
10
- def self.registered(app)
11
- Sequel::Model.plugin(:schema)
12
- app.configure(:development) { Sequel.connect("sqlite3://" + Padrino.root('db', "development.db"), :loggers => [logger]) }
13
- app.configure(:production) { Sequel.connect("sqlite3://" + Padrino.root('db', "production.db"), :loggers => [logger]) }
14
- app.configure(:test) { Sequel.connect("sqlite3://" + Padrino.root('db', "test.db"), :loggers => [logger]) }
15
- end
9
+ Sequel::Model.plugin(:schema)
10
+ case Padrino.env
11
+ when :development then Sequel.connect("sqlite3://" + Padrino.root('db', "development.db"), :loggers => [logger])
12
+ when :production then Sequel.connect("sqlite3://" + Padrino.root('db', "production.db"), :loggers => [logger])
13
+ when :test then Sequel.connect("sqlite3://" + Padrino.root('db', "test.db"), :loggers => [logger])
16
14
  end
17
15
  SEQUEL
18
16
 
@@ -29,8 +27,7 @@ module Padrino
29
27
  MODEL
30
28
 
31
29
  def create_model_file(name, fields)
32
- model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
33
- return false if File.exist?(model_path)
30
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
34
31
  model_contents = SQ_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
35
32
  create_file(model_path, model_contents)
36
33
  end
@@ -19,8 +19,7 @@ module Padrino
19
19
 
20
20
  def setup_renderer
21
21
  require_dependencies 'haml'
22
- create_file 'config/initializers/sass.rb', SASS_INIT
23
- empty_directory 'public/stylesheets/sass'
22
+ create_file destination_root('/config/initializers/sass.rb'), SASS_INIT
24
23
  end
25
24
  end
26
25
 
@@ -5,8 +5,8 @@ module Padrino
5
5
 
6
6
  module JqueryGen
7
7
  def setup_script
8
- copy_file('templates/scripts/jquery.js', "public/javascripts/jquery.js")
9
- create_file('public/javascripts/application.js', "// Put your application scripts here")
8
+ copy_file('templates/scripts/jquery.js', destination_root("/app/public/javascripts/jquery.js"))
9
+ create_file(destination_root('/app/public/javascripts/application.js'), "// Put your application scripts here")
10
10
  end
11
11
  end
12
12
 
@@ -5,9 +5,9 @@ module Padrino
5
5
 
6
6
  module PrototypeGen
7
7
  def setup_script
8
- copy_file('templates/scripts/protopak.js', "public/javascripts/protopak.js")
9
- copy_file('templates/scripts/lowpro.js', "public/javascripts/lowpro.js")
10
- create_file('public/javascripts/application.js', "// Put your application scripts here")
8
+ copy_file('templates/scripts/protopak.js', destination_root("/app/public/javascripts/protopak.js"))
9
+ copy_file('templates/scripts/lowpro.js', destination_root("/app/public/javascripts/lowpro.js"))
10
+ create_file(destination_root('/app/public/javascripts/application.js'), "// Put your application scripts here")
11
11
  end
12
12
  end
13
13
 
@@ -5,12 +5,10 @@ module Padrino
5
5
 
6
6
  module RightjsGen
7
7
  def setup_script
8
- copy_file('templates/scripts/right.js', "public/javascripts/right.js")
9
- create_file('public/javascripts/application.js', "// Put your application scripts here")
8
+ copy_file('templates/scripts/right.js', destination_root("/app/public/javascripts/right.js"))
9
+ create_file(destination_root('/app/public/javascripts/application.js'), "// Put your application scripts here")
10
10
  end
11
11
  end
12
-
13
-
14
12
  end
15
13
  end
16
14
  end
@@ -32,9 +32,9 @@ module Padrino
32
32
  TEST
33
33
 
34
34
  # Generates a controller test given the controllers name
35
- def generate_controller_test(name, root)
35
+ def generate_controller_test(name)
36
36
  bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
37
- create_file app_root_path("test/controllers/","#{name}_controller_test.rb"), bacon_contents, :skip => true
37
+ create_file destination_root("test/controllers/","#{name}_controller_test.rb"), bacon_contents, :skip => true
38
38
  end
39
39
 
40
40
  BACON_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -50,7 +50,7 @@ module Padrino
50
50
 
51
51
  def generate_model_test(name)
52
52
  bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
53
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), bacon_contents, :skip => true
53
+ create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), bacon_contents, :skip => true
54
54
  end
55
55
 
56
56
  end
@@ -31,9 +31,9 @@ module Padrino
31
31
  TEST
32
32
 
33
33
  # Generates a controller test given the controllers name
34
- def generate_controller_test(name, root)
34
+ def generate_controller_test(name)
35
35
  riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
36
- create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), riot_contents, :skip => true
36
+ create_file destination_root("test/controllers/#{name}_controller_test.rb"), riot_contents, :skip => true
37
37
  end
38
38
 
39
39
  RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -49,7 +49,7 @@ module Padrino
49
49
 
50
50
  def generate_model_test(name)
51
51
  riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
52
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), riot_contents, :skip => true
52
+ create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), riot_contents, :skip => true
53
53
  end
54
54
 
55
55
  end
@@ -33,9 +33,9 @@ module Padrino
33
33
 
34
34
  # TODO move to spec directory to follow convention
35
35
  # Generates a controller test given the controllers name
36
- def generate_controller_test(name, root)
36
+ def generate_controller_test(name)
37
37
  rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
38
- create_file File.join(root, "test/controllers/#{name}_controller_spec.rb"), rspec_contents, :skip => true
38
+ create_file destination_root("test/controllers/#{name}_controller_spec.rb"), rspec_contents, :skip => true
39
39
  end
40
40
 
41
41
  RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -51,7 +51,7 @@ module Padrino
51
51
 
52
52
  def generate_model_test(name)
53
53
  rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
54
- create_file app_root_path("test/models/#{name.to_s.downcase}_spec.rb"), rspec_contents, :skip => true
54
+ create_file destination_root("test/models/#{name.to_s.downcase}_spec.rb"), rspec_contents, :skip => true
55
55
  end
56
56
 
57
57
  end
@@ -36,9 +36,9 @@ module Padrino
36
36
  TEST
37
37
 
38
38
  # Generates a controller test given the controllers name
39
- def generate_controller_test(name, root)
39
+ def generate_controller_test(name)
40
40
  shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
41
- create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), shoulda_contents, :skip => true
41
+ create_file destination_root("test/controllers/#{name}_controller_test.rb"), shoulda_contents, :skip => true
42
42
  end
43
43
 
44
44
  SHOULDA_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -56,7 +56,7 @@ module Padrino
56
56
 
57
57
  def generate_model_test(name)
58
58
  shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
59
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), shoulda_contents, :skip => true
59
+ create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), shoulda_contents, :skip => true
60
60
  end
61
61
 
62
62
  end
@@ -31,9 +31,9 @@ module Padrino
31
31
  TEST
32
32
 
33
33
  # Generates a controller test given the controllers name
34
- def generate_controller_test(name, root)
34
+ def generate_controller_test(name)
35
35
  testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
36
- create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), testspec_contents, :skip => true
36
+ create_file destination_root("test/controllers/#{name}_controller_test.rb"), testspec_contents, :skip => true
37
37
  end
38
38
 
39
39
  TESTSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -49,7 +49,7 @@ module Padrino
49
49
 
50
50
  def generate_model_test(name)
51
51
  tests_contents = TESTSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
52
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), tests_contents, :skip => true
52
+ create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), tests_contents, :skip => true
53
53
  end
54
54
 
55
55
  end
@@ -21,7 +21,7 @@ module Padrino
21
21
 
22
22
  argument :name, :desc => "The name of your padrino controller"
23
23
  argument :fields, :desc => "The fields for the controller", :type => :array, :default => []
24
- class_option :root, :aliases => '-r', :default => nil, :type => :string
24
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
25
25
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
26
26
 
27
27
  # Show help if no argv given
@@ -31,16 +31,17 @@ module Padrino
31
31
  end
32
32
 
33
33
  def create_controller
34
- if in_app_root?(options[:root])
34
+ self.destination_root = options[:root]
35
+ if in_app_root?
35
36
  @app_name = fetch_app_name(options[:root])
36
37
  @actions = controller_actions(fields)
37
38
  self.behavior = :revoke if options[:destroy]
38
- # inject_into_file app_root_path("config/urls.rb"), controller_routes(name,fields), :after => "urls do\n"
39
- template "templates/controller.rb.tt", app_root_path("app/controllers", "#{name}.rb")
40
- template "templates/helper.rb.tt", app_root_path("app/helpers", "#{name}_helper.rb")
41
- empty_directory app_root_path("app/views/#{name}")
42
- include_component_module_for(:test, options[:root])
43
- generate_controller_test(name, options[:root] || '.')
39
+ # inject_into_file destination_root("config/urls.rb"), controller_routes(name,fields), :after => "urls do\n"
40
+ template "templates/controller.rb.tt", destination_root("app/controllers", "#{name}.rb")
41
+ template "templates/helper.rb.tt", destination_root("app/helpers", "#{name}_helper.rb")
42
+ empty_directory destination_root("app/views/#{name}")
43
+ include_component_module_for(:test)
44
+ generate_controller_test(name)
44
45
  else
45
46
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
46
47
  end
@@ -20,7 +20,7 @@ module Padrino
20
20
  desc "Description:\n\n\tpadrino-gen mailer generates a new Padrino mailer"
21
21
 
22
22
  argument :name, :desc => "The name of your padrino mailer"
23
- class_option :root, :aliases => '-r', :default => nil, :type => :string
23
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
24
24
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
25
 
26
26
  # Show help if no argv given
@@ -30,14 +30,15 @@ module Padrino
30
30
  end
31
31
 
32
32
  def create_mailer
33
- if in_app_root?(options[:root])
33
+ self.destination_root = options[:root]
34
+ if in_app_root?
34
35
  self.behavior = :revoke if options[:destroy]
35
36
  simple_name = name.to_s.gsub(/mailer/i, '')
36
37
  @mailer_basename = "#{simple_name.downcase.underscore}_mailer"
37
38
  @mailer_klass = "#{simple_name.downcase.camelize}Mailer"
38
- template "templates/mailer_initializer.rb.tt", app_root_path("config/initializers/mailer.rb"), :skip => true
39
- template "templates/mailer.rb.tt", app_root_path("app/mailers", "#{@mailer_basename}.rb")
40
- empty_directory app_root_path('app/views/', @mailer_basename)
39
+ template "templates/mailer_initializer.rb.tt", destination_root("config/initializers/mailer.rb"), :skip => true
40
+ template "templates/mailer.rb.tt", destination_root("app/mailers", "#{@mailer_basename}.rb")
41
+ empty_directory destination_root('app/views/', @mailer_basename)
41
42
  else
42
43
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
43
44
  end
@@ -21,7 +21,7 @@ module Padrino
21
21
 
22
22
  argument :name, :desc => "The name of your padrino migration"
23
23
  argument :columns, :desc => "The columns for the migration", :type => :array, :default => []
24
- class_option :root, :aliases => '-r', :default => nil, :type => :string
24
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
25
25
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
26
26
 
27
27
  # Show help if no argv given
@@ -30,11 +30,11 @@ module Padrino
30
30
  super
31
31
  end
32
32
 
33
- def create_model
34
- if in_app_root?(options[:root])
35
- remove_migration(name) if options[:destroy]
36
- include_component_module_for(:orm, options[:root])
33
+ def create_migration
34
+ self.destination_root = options[:root]
35
+ if in_app_root?
37
36
  self.behavior = :revoke if options[:destroy]
37
+ include_component_module_for(:orm)
38
38
  create_migration_file(name, name, columns)
39
39
  else
40
40
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
@@ -21,7 +21,7 @@ module Padrino
21
21
 
22
22
  argument :name, :desc => "The name of your padrino model"
23
23
  argument :fields, :desc => "The fields for the model", :type => :array, :default => []
24
- class_option :root, :aliases => '-r', :default => nil, :type => :string
24
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
25
25
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
26
26
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
27
27
 
@@ -32,11 +32,11 @@ module Padrino
32
32
  end
33
33
 
34
34
  def create_model
35
- if in_app_root?(options[:root])
36
- remove_model_migration(name) if options[:destroy]
35
+ self.destination_root = options[:root]
36
+ if in_app_root?
37
37
  self.behavior = :revoke if options[:destroy]
38
- include_component_module_for(:orm, options[:root])
39
- include_component_module_for(:test, options[:root])
38
+ include_component_module_for(:orm)
39
+ include_component_module_for(:test)
40
40
  migration_name = "create_#{name.pluralize.underscore}"
41
41
  create_model_file(name, fields)
42
42
  generate_model_test(name)
@@ -24,22 +24,26 @@ module Padrino
24
24
  # Include related modules
25
25
  include Thor::Actions
26
26
 
27
- class_option :root, :aliases => '-r', :default => nil, :type => :string
27
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => nil, :type => :string
28
28
 
29
29
  # We need to TRY to load boot because some of our app dependencies maybe have
30
30
  # custom generators, so is necessary know who are.
31
31
  def load_boot
32
- if options[:root]
33
- require File.join(options[:root], 'config/boot.rb') if File.exist?(File.join(options[:root], 'config/boot.rb'))
34
- else
35
- require 'config/boot.rb' if File.exist?('config/boot.rb')
32
+ require 'padrino-gen/generators/actions'
33
+ Dir[File.dirname(__FILE__) + '/generators/{components}/**/*.rb'].each { |lib| require lib }
34
+
35
+ begin
36
+ if options[:root]
37
+ require File.join(options[:root], 'config/boot.rb') if File.exist?(File.join(options[:root], 'config/boot.rb'))
38
+ else
39
+ require 'config/boot.rb' if File.exist?('config/boot.rb')
40
+ end
41
+ rescue Exception => e
42
+ puts "=> Problem loading config/boot.rb"
36
43
  end
37
44
  end
38
45
 
39
46
  def setup
40
- require 'padrino-gen/generators/actions'
41
- Dir[File.dirname(__FILE__) + '/generators/{components}/**/*.rb'].each { |lib| require lib }
42
-
43
47
  Padrino::Generators.lockup!
44
48
 
45
49
  generator_kind = ARGV.delete_at(0).to_s.downcase.to_sym if ARGV[0].present?
@@ -15,7 +15,7 @@ if defined?(ActiveRecord)
15
15
  # development:
16
16
  # database: blog_development
17
17
  # <<: *defaults
18
- next unless config['database']
18
+ next unless config[:database]
19
19
  # Only connect to local databases
20
20
  local_database?(config) { create_database(config) }
21
21
  end
@@ -29,12 +29,13 @@ if defined?(ActiveRecord)
29
29
 
30
30
  def create_database(config)
31
31
  begin
32
- if config['adapter'] =~ /sqlite/
33
- if File.exist?(config['database'])
34
- $stderr.puts "#{config['database']} already exists"
32
+ if config[:adapter] =~ /sqlite/
33
+ if File.exist?(config[:database])
34
+ $stderr.puts "#{config[:database]} already exists"
35
35
  else
36
36
  begin
37
37
  # Create the SQLite database
38
+ Dir.mkdir File.dirname(config[:database])
38
39
  ActiveRecord::Base.establish_connection(config)
39
40
  ActiveRecord::Base.connection
40
41
  rescue
@@ -48,38 +49,38 @@ if defined?(ActiveRecord)
48
49
  ActiveRecord::Base.connection
49
50
  end
50
51
  rescue
51
- case config['adapter']
52
+ case config[:adapter]
52
53
  when 'mysql'
53
54
  @charset = ENV['CHARSET'] || 'utf8'
54
55
  @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
55
- creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
56
+ creation_options = {:charset => (config[:charset] || @charset), :collation => (config[:collation] || @collation)}
56
57
  begin
57
- ActiveRecord::Base.establish_connection(config.merge('database' => nil))
58
- ActiveRecord::Base.connection.create_database(config['database'], creation_options)
58
+ ActiveRecord::Base.establish_connection(config.merge(:database => nil))
59
+ ActiveRecord::Base.connection.create_database(config[:database], creation_options)
59
60
  ActiveRecord::Base.establish_connection(config)
60
61
  rescue Mysql::Error => sqlerr
61
62
  if sqlerr.errno == Mysql::Error::ER_ACCESS_DENIED_ERROR
62
63
  print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
63
64
  root_password = $stdin.gets.strip
64
- grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \
65
- "TO '#{config['username']}'@'localhost' " \
66
- "IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;"
65
+ grant_statement = "GRANT ALL PRIVILEGES ON #{config[:database]}.* " \
66
+ "TO '#{config[:username]}'@'localhost' " \
67
+ "IDENTIFIED BY '#{config[:password]}' WITH GRANT OPTION;"
67
68
  ActiveRecord::Base.establish_connection(config.merge(
68
- 'database' => nil, 'username' => 'root', 'password' => root_password))
69
- ActiveRecord::Base.connection.create_database(config['database'], creation_options)
69
+ :database => nil, 'username' => 'root', 'password' => root_password))
70
+ ActiveRecord::Base.connection.create_database(config[:database], creation_options)
70
71
  ActiveRecord::Base.connection.execute grant_statement
71
72
  ActiveRecord::Base.establish_connection(config)
72
73
  else
73
74
  $stderr.puts sqlerr.error
74
- $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation}"
75
- $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
75
+ $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config[:charset] || @charset}, collation: #{config[:collation] || @collation}"
76
+ $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config[:charset]
76
77
  end
77
78
  end
78
79
  when 'postgresql'
79
80
  @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
80
81
  begin
81
- ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
82
- ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
82
+ ActiveRecord::Base.establish_connection(config.merge(:database => 'postgres', 'schema_search_path' => 'public'))
83
+ ActiveRecord::Base.connection.create_database(config[:database], config.merge('encoding' => @encoding))
83
84
  ActiveRecord::Base.establish_connection(config)
84
85
  rescue
85
86
  $stderr.puts $!, *($!.backtrace)
@@ -87,7 +88,7 @@ if defined?(ActiveRecord)
87
88
  end
88
89
  end
89
90
  else
90
- $stderr.puts "#{config['database']} already exists"
91
+ $stderr.puts "#{config[:database]} already exists"
91
92
  end
92
93
  end
93
94
 
@@ -96,12 +97,12 @@ if defined?(ActiveRecord)
96
97
  task :all => :environment do
97
98
  ActiveRecord::Base.configurations.each_value do |config|
98
99
  # Skip entries that don't have a database key
99
- next unless config['database']
100
+ next unless config[:database]
100
101
  begin
101
102
  # Only connect to local databases
102
103
  local_database?(config) { drop_database(config) }
103
104
  rescue Exception => e
104
- puts "Couldn't drop #{config['database']} : #{e.inspect}"
105
+ puts "Couldn't drop #{config[:database]} : #{e.inspect}"
105
106
  end
106
107
  end
107
108
  end
@@ -113,15 +114,15 @@ if defined?(ActiveRecord)
113
114
  begin
114
115
  drop_database(config)
115
116
  rescue Exception => e
116
- puts "Couldn't drop #{config['database']} : #{e.inspect}"
117
+ puts "Couldn't drop #{config[:database]} : #{e.inspect}"
117
118
  end
118
119
  end
119
120
 
120
121
  def local_database?(config, &block)
121
- if %w( 127.0.0.1 localhost ).include?(config['host']) || config['host'].blank?
122
+ if %w( 127.0.0.1 localhost ).include?(config[:host]) || config[:host].blank?
122
123
  yield
123
124
  else
124
- puts "This task only modifies local databases. #{config['database']} is on a remote host."
125
+ puts "This task only modifies local databases. #{config[:database]} is on a remote host."
125
126
  end
126
127
  end
127
128
 
@@ -185,7 +186,7 @@ if defined?(ActiveRecord)
185
186
  desc "Retrieves the charset for the current environment's database"
186
187
  task :charset => :environment do
187
188
  config = ActiveRecord::Base.configurations[Padrino.env || 'development']
188
- case config['adapter']
189
+ case config[:adapter]
189
190
  when 'mysql'
190
191
  ActiveRecord::Base.establish_connection(config)
191
192
  puts ActiveRecord::Base.connection.charset
@@ -200,7 +201,7 @@ if defined?(ActiveRecord)
200
201
  desc "Retrieves the collation for the current environment's database"
201
202
  task :collation => :environment do
202
203
  config = ActiveRecord::Base.configurations[Padrino.env || 'development']
203
- case config['adapter']
204
+ case config[:adapter]
204
205
  when 'mysql'
205
206
  ActiveRecord::Base.establish_connection(config)
206
207
  puts ActiveRecord::Base.connection.collation
@@ -294,19 +295,19 @@ if defined?(ActiveRecord)
294
295
  end
295
296
 
296
297
  def drop_database(config)
297
- case config['adapter']
298
+ case config[:adapter]
298
299
  when 'mysql'
299
300
  ActiveRecord::Base.establish_connection(config)
300
- ActiveRecord::Base.connection.drop_database config['database']
301
+ ActiveRecord::Base.connection.drop_database config[:database]
301
302
  when /^sqlite/
302
303
  require 'pathname'
303
- path = Pathname.new(config['database'])
304
+ path = Pathname.new(config[:database])
304
305
  file = path.absolute? ? path.to_s : Padrino.root(path)
305
306
 
306
307
  FileUtils.rm(file)
307
308
  when 'postgresql'
308
- ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
309
- ActiveRecord::Base.connection.drop_database config['database']
309
+ ActiveRecord::Base.establish_connection(config.merge(:database => 'postgres', 'schema_search_path' => 'public'))
310
+ ActiveRecord::Base.connection.drop_database config[:database]
310
311
  end
311
312
  end
312
313
 
@@ -315,8 +316,8 @@ if defined?(ActiveRecord)
315
316
  end
316
317
 
317
318
  def set_firebird_env(config)
318
- ENV["ISC_USER"] = config["username"].to_s if config["username"]
319
- ENV["ISC_PASSWORD"] = config["password"].to_s if config["password"]
319
+ ENV["ISC_USER"] = config[:username].to_s if config[:username]
320
+ ENV["ISC_PASSWORD"] = config[:password].to_s if config[:password]
320
321
  end
321
322
 
322
323
  def firebird_db_string(config)
data/lib/padrino-gen.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'padrino-core/support_lite'
2
2
  require 'padrino-gen/generators'
3
+
4
+ ##
3
5
  # Add our rakes when padrino core require this file.
6
+ #
4
7
  require 'padrino-core/tasks'
5
8
  Padrino::Tasks.files << Dir[File.dirname(__FILE__) + "/padrino-gen/padrino-tasks/**/*.rb"]
data/padrino-gen.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-gen}
8
- s.version = "0.6.3"
8
+ s.version = "0.6.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2010-01-15}
12
+ s.date = %q{2010-01-26}
13
13
  s.default_executable = %q{padrino-gen}
14
14
  s.description = %q{Generators for easily creating and building padrino applications from the console}
15
15
  s.email = %q{nesquena@gmail.com}
@@ -98,7 +98,7 @@ Gem::Specification.new do |s|
98
98
 
99
99
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
100
100
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
101
- s.add_runtime_dependency(%q<padrino-core>, ["= 0.6.3"])
101
+ s.add_runtime_dependency(%q<padrino-core>, ["= 0.6.7"])
102
102
  s.add_runtime_dependency(%q<thor>, [">= 0.11.8"])
103
103
  s.add_runtime_dependency(%q<bundler>, [">= 0.5.0"])
104
104
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
@@ -109,7 +109,7 @@ Gem::Specification.new do |s|
109
109
  s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
110
110
  else
111
111
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
112
- s.add_dependency(%q<padrino-core>, ["= 0.6.3"])
112
+ s.add_dependency(%q<padrino-core>, ["= 0.6.7"])
113
113
  s.add_dependency(%q<thor>, [">= 0.11.8"])
114
114
  s.add_dependency(%q<bundler>, [">= 0.5.0"])
115
115
  s.add_dependency(%q<haml>, [">= 2.2.1"])
@@ -121,7 +121,7 @@ Gem::Specification.new do |s|
121
121
  end
122
122
  else
123
123
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
124
- s.add_dependency(%q<padrino-core>, ["= 0.6.3"])
124
+ s.add_dependency(%q<padrino-core>, ["= 0.6.7"])
125
125
  s.add_dependency(%q<thor>, [">= 0.11.8"])
126
126
  s.add_dependency(%q<bundler>, [">= 0.5.0"])
127
127
  s.add_dependency(%q<haml>, [">= 2.2.1"])
data/test/helper.rb CHANGED
@@ -9,7 +9,7 @@ require 'thor'
9
9
  # We try to load the vendored padrino-core if exist
10
10
  %w(core).each do |gem|
11
11
  if File.exist?(File.dirname(__FILE__) + "/../../padrino-#{gem}/lib")
12
- $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../padrino-#{gem}/lib"
12
+ $:.unshift File.dirname(__FILE__) + "/../../padrino-#{gem}/lib"
13
13
  end
14
14
  end
15
15