lib/lotus/commands/generate.rb in lotusrb-0.3.0 vs lib/lotus/commands/generate.rb in lotusrb-0.3.1
- old
+ new
@@ -8,10 +8,12 @@
# @api private
class Generate
# @since 0.3.0
# @api private
GENERATORS_NAMESPACE = "Lotus::Generators::%s".freeze
+ APP = 'app'.freeze
+ SLICE_TYPE = 'slice'.freeze
# @since 0.3.0
# @api private
class Error < ::StandardError
end
@@ -22,20 +24,19 @@
# @since 0.3.0
# @api private
def initialize(type, app_name, name, env, cli)
@cli = cli
- @options = env.to_options.merge(cli.options)
-
- @app_name = app_name
- @app = Utils::String.new(@app_name).classify
-
@name = name
- @type = type
+ @type = sanitize_type(type)
+ @app_name = app_name
@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
@@ -55,16 +56,38 @@
# @api private
def spec_root
@spec_root ||= Pathname.new('spec')
end
+ # @since 0.3.1
+ # @api private
+ def model_root
+ @model_root ||= Pathname.new(['lib', ::File.basename(Dir.getwd)]
+ .join(::File::SEPARATOR))
+ end
+
private
# @since 0.3.0
# @api private
def generator
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
end
end
end
end