lib/lotus/commands/generate.rb in lotusrb-0.3.2 vs lib/lotus/commands/generate.rb in lotusrb-0.4.0
- old
+ new
@@ -8,35 +8,36 @@
# @api private
class Generate
# @since 0.3.0
# @api private
GENERATORS_NAMESPACE = "Lotus::Generators::%s".freeze
- APP = 'app'.freeze
- SLICE_TYPE = 'slice'.freeze
+ APP_ARCHITECTURE = 'app'.freeze
# @since 0.3.0
# @api private
class Error < ::StandardError
end
# @since 0.3.0
# @api private
- attr_reader :cli, :source, :target, :app, :app_name, :name, :options
+ attr_reader :cli, :source, :target, :app, :app_name, :name, :options, :env
# @since 0.3.0
# @api private
def initialize(type, app_name, name, env, cli)
@cli = cli
+ @env = env
@name = name
+ @options = env.to_options.merge(cli.options)
- @type = sanitize_type(type)
- @app_name = app_name
+ sanitize_input(app_name, name)
+ @type = type
+
@source = Pathname.new(::File.dirname(__FILE__) + "/../generators/#{ @type }/").realpath
@target = Pathname.pwd.realpath
@app = Utils::String.new(@app_name).classify
- @options = sanitize_app_name_options(app_name).merge(env.to_options.merge(cli.options))
end
# @since 0.3.0
# @api private
def start
@@ -47,11 +48,15 @@
end
# @since 0.3.0
# @api private
def app_root
- @app_root ||= Pathname.new([@options[:path], @app_name].join(::File::SEPARATOR))
+ @app_root ||= begin
+ result = Pathname.new(@options[:apps_path])
+ result = result.join(@app_name) if @env.container?
+ result
+ end
end
# @since 0.3.0
# @api private
def spec_root
@@ -72,22 +77,17 @@
require "lotus/generators/#{ @type }"
class_name = Utils::String.new(@type).classify
Utils::Class.load!(GENERATORS_NAMESPACE % class_name).new(self)
end
- # @since 0.3.1
- # @api private
- def sanitize_app_name_options(app_name)
- {
- application: app_name,
- application_base_url: "/#{app_name}"
- }
- end
-
- # @since 0.3.1
- # @api private
- def sanitize_type(type)
- type == APP ? SLICE_TYPE : type
+ def sanitize_input(app_name, name)
+ if options[:architecture] == APP_ARCHITECTURE
+ @app_name = nil
+ @name = app_name
+ else
+ @app_name = app_name
+ @name = name
+ end
end
end
end
end