lib/hanami/commands/generate/app.rb in hanami-0.8.0 vs lib/hanami/commands/generate/app.rb in hanami-0.9.0
- old
+ new
@@ -1,20 +1,26 @@
require 'hanami/commands/generate/abstract'
require 'hanami/application_name'
+require 'hanami/utils/blank'
require 'securerandom'
module Hanami
module Commands
class Generate
class App < Abstract
attr_reader :base_path
def initialize(options, application_name)
- super(options)
+ @environment = Hanami::Environment.new(options)
+ @options = Hanami::Utils::Hash.new(options).symbolize!
+ assert_options!
+
+ @target_path = Hanami.root
assert_application_name!(application_name)
assert_architecture!
+ assert_application_base_url!
@application_name = ApplicationName.new(application_name)
@base_path = Pathname.pwd
end
@@ -63,11 +69,11 @@
"\nrequire_relative '../apps/#{ app_name }/application'"
end
end
def add_mount_app
- generator.inject_into_file base_path.join('config/environment.rb'), after: /Hanami::Container.configure do/ do |match|
+ generator.inject_into_file base_path.join('config/environment.rb'), after: /Hanami.configure do/ do |match|
"\n mount #{ classified_app_name }::Application, at: '#{ application_base_url }'"
end
end
def add_web_session_secret
@@ -110,9 +116,16 @@
end
def assert_architecture!
if !environment.container?
raise ArgumentError.new('App generator is only available for container architecture.')
+ end
+ end
+
+ def assert_application_base_url!
+ if options.key?(:application_base_url) && Utils::Blank.blank?(options[:application_base_url])
+ warn "`' is not a valid URL"
+ exit(1)
end
end
end
end
end