lib/lotus/generators/action.rb in lotusrb-0.3.1 vs lib/lotus/generators/action.rb in lotusrb-0.3.2
- old
+ new
@@ -25,21 +25,23 @@
# @since 0.3.0
# @api private
def initialize(command)
super
- @controller, @action = name.split(ACTION_SEPARATOR)
+ @name = Utils::String.new(name).underscore
+ @controller, @action = @name.split(ACTION_SEPARATOR)
@controller_name = Utils::String.new(@controller).classify
@action_name = Utils::String.new(@action).classify
cli.class.source_root(source)
end
# @since 0.3.0
# @api private
def start
assert_existing_app!
+ assert_action!
opts = {
app: app,
controller: @controller_name,
action: @action_name,
@@ -86,20 +88,28 @@
unless target.join(app_root).exist?
raise Lotus::Commands::Generate::Error.new("Unknown app: `#{ app_name }'")
end
end
+ # @since 0.3.2
+ # @api private
+ def assert_action!
+ if @action.nil?
+ raise Lotus::Commands::Generate::Error.new("Unknown action, please add action's name with this syntax controller_name#action_name")
+ end
+ end
+
# @since 0.3.0
# @api private
def generate_route
path = target.join(_routes_path)
path.dirname.mkpath
FileUtils.touch(path)
# Insert at the top of the file
cli.insert_into_file _routes_path, before: /\A(.*)/ do
- "get '/#{ @controller }', to: '#{ name }'\n"
+ "get '/#{ @controller }', to: '#{ @name }'\n"
end
end
# @since 0.3.0
# @api private