lib/lotus/generators/action.rb in lotusrb-0.4.0 vs lib/lotus/generators/action.rb in lotusrb-0.4.1
- old
+ new
@@ -8,10 +8,18 @@
class Action < Abstract
# @since 0.3.0
# @api private
ACTION_SEPARATOR = /\/|\#/
+ # @since 0.4.1
+ # @api private
+ ROUTE_ENDPOINT_SEPARATOR = '#'.freeze
+
+ # @since 0.4.1
+ # @api private
+ QUOTED_NAME = /(\"|\'|\\)/
+
# @since 0.3.0
# @api private
SUFFIX = '.rb'.freeze
# @since 0.3.0
@@ -25,11 +33,11 @@
# @since 0.3.0
# @api private
def initialize(command)
super
- @name = Utils::String.new(name).underscore
+ @name = Utils::String.new(name).underscore.gsub(QUOTED_NAME, '')
@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)
@@ -117,17 +125,23 @@
FileUtils.touch(path)
# Insert at the top of the file
cli.insert_into_file _routes_path, before: /\A(.*)/ do
- "get '#{ _route_url }', to: '#{ @name }'\n"
+ "get '#{ _route_url }', to: '#{ _route_endpoint }'\n"
end
end
# @since 0.4.0
# @api private
def _route_url
options.fetch(:url, "/#{ @controller }")
+ end
+
+ # @since 0.4.1
+ # @api private
+ def _route_endpoint
+ "#{ @controller }#{ROUTE_ENDPOINT_SEPARATOR}#{ @action }"
end
# @since 0.3.0
# @api private
def _routes_path