lib/hanami/cli/generators/app/action.rb in hanami-cli-2.2.0.beta2 vs lib/hanami/cli/generators/app/action.rb in hanami-cli-2.2.0.rc1

- old
+ new

@@ -19,16 +19,16 @@ @inflector = inflector end # @since 2.0.0 # @api private - def call(app, controller, action, url, http, format, skip_view, slice, context: nil) + def call(app, controller, action, url, http, format, skip_view, skip_route, slice, context: nil) context ||= ActionContext.new(inflector, app, slice, controller, action) if slice - generate_for_slice(controller, action, url, http, format, skip_view, slice, context) + generate_for_slice(controller, action, url, http, format, skip_view, skip_route, slice, context) else - generate_for_app(controller, action, url, http, format, skip_view, context) + generate_for_app(controller, action, url, http, format, skip_view, skip_route, context) end end private @@ -70,19 +70,21 @@ attr_reader :fs attr_reader :inflector # rubocop:disable Metrics/AbcSize - def generate_for_slice(controller, action, url, http, format, skip_view, slice, context) + def generate_for_slice(controller, action, url, http, format, skip_view, skip_route, slice, context) slice_directory = fs.join("slices", slice) raise MissingSliceError.new(slice) unless fs.directory?(slice_directory) - fs.inject_line_at_block_bottom( - fs.join("config", "routes.rb"), - slice_matcher(slice), - route(controller, action, url, http) - ) + if generate_route?(skip_route) + fs.inject_line_at_block_bottom( + fs.join("config", "routes.rb"), + slice_matcher(slice), + route(controller, action, url, http) + ) + end fs.mkdir(directory = fs.join(slice_directory, "actions", controller)) fs.write(fs.join(directory, "#{action}.rb"), t("slice_action.erb", context)) if generate_view?(skip_view, action, directory) @@ -93,16 +95,18 @@ fs.write(fs.join(directory, "#{action}.#{format}.erb"), t(template_with_format_ext("slice_template", format), context)) end end - def generate_for_app(controller, action, url, http, format, skip_view, context) - fs.inject_line_at_class_bottom( - fs.join("config", "routes.rb"), - "class Routes", - route(controller, action, url, http) - ) + def generate_for_app(controller, action, url, http, format, skip_view, skip_route, context) + if generate_route?(skip_route) + fs.inject_line_at_class_bottom( + fs.join("config", "routes.rb"), + "class Routes", + route(controller, action, url, http) + ) + end fs.mkdir(directory = fs.join("app", "actions", controller)) fs.write(fs.join(directory, "#{action}.rb"), t("action.erb", context)) view = action @@ -131,9 +135,17 @@ # @api private # @since 2.1.0 def generate_view?(skip_view, view, directory) return false if skip_view return generate_restful_view?(view, directory) if rest_view?(view) + + true + end + + # @api private + # @since 2.2.0 + def generate_route?(skip_route) + return false if skip_route true end # @api private