lib/lotus/generators/application/container.rb in lotusrb-0.3.2 vs lib/lotus/generators/application/container.rb in lotusrb-0.4.0
- old
+ new
@@ -11,11 +11,11 @@
@slice_generator = Slice.new(command)
@lotus_head = options.fetch(:lotus_head)
@test = options[:test]
@database = options[:database]
- @lotus_model_version = '~> 0.3'
+ @lotus_model_version = '~> 0.4'
cli.class.source_root(source)
end
def start
@@ -28,27 +28,32 @@
database_config: database_config,
lotus_model_version: @lotus_model_version,
}
templates = {
- 'lotusrc.tt' => '.lotusrc',
- 'Gemfile.tt' => 'Gemfile',
- 'config.ru.tt' => 'config.ru',
- 'config/environment.rb.tt' => 'config/environment.rb',
- 'config/.env.tt' => 'config/.env',
- 'config/.env.development.tt' => 'config/.env.development',
- 'config/.env.test.tt' => 'config/.env.test',
- 'lib/app_name.rb.tt' => "lib/#{ app_name }.rb",
- 'lib/config/mapping.rb.tt' => 'lib/config/mapping.rb',
+ 'lotusrc.tt' => '.lotusrc',
+ '.env.tt' => '.env',
+ '.env.development.tt' => '.env.development',
+ '.env.test.tt' => '.env.test',
+ 'Gemfile.tt' => 'Gemfile',
+ 'config.ru.tt' => 'config.ru',
+ 'config/environment.rb.tt' => 'config/environment.rb',
+ 'lib/app_name.rb.tt' => "lib/#{ app_name }.rb",
+ 'lib/config/mapping.rb.tt' => 'lib/config/mapping.rb',
}
empty_directories = [
- "db",
"lib/#{ app_name }/entities",
"lib/#{ app_name }/repositories"
]
+ empty_directories << if sql_database?
+ "db/migrations"
+ else
+ "db"
+ end
+
case options[:test]
when 'rspec'
templates.merge!(
'Rakefile.rspec.tt' => 'Rakefile',
'rspec.rspec.tt' => '.rspec',
@@ -62,10 +67,16 @@
'spec_helper.rb.minitest.tt' => 'spec/spec_helper.rb',
'features_helper.rb.minitest.tt' => 'spec/features_helper.rb'
)
end
+ if sql_database?
+ templates.merge!(
+ 'schema.sql.tt' => 'db/schema.sql'
+ )
+ end
+
empty_directories << [
"spec/#{ app_name }/entities",
"spec/#{ app_name }/repositories",
"spec/support"
]
@@ -121,14 +132,18 @@
when 'memory'
:memory
end
end
+ def sql_database?
+ database_type == :sql
+ end
+
def database_uri
{
- development: "#{database_base_uri}_development",
- test: "#{database_base_uri}_test"
+ development: database_environment_uri(:development),
+ test: database_environment_uri(:test)
}
end
def database_base_uri
case @database
@@ -142,9 +157,18 @@
"sqlite://db/#{Shellwords.escape(app_name)}"
when 'memory'
"memory://localhost/#{app_name}"
else
"file:///db/#{app_name}"
+ end
+ end
+
+ def database_environment_uri(environment)
+ case @database
+ when 'sqlite', 'sqlite3'
+ "#{database_base_uri}_#{environment}.sqlite"
+ else
+ "#{database_base_uri}_#{environment}"
end
end
end
end
end