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

- old
+ new

@@ -1,32 +1,38 @@ # frozen_string_literal: true require "erb" require "dry/files" -require "hanami/cli/files" -require "hanami/cli/generators/app/action_context" -require "hanami/cli/url" +require_relative "../../errors" # rubocop:disable Metrics/ParameterLists module Hanami module CLI module Generators module App + # @since 2.0.0 + # @api private class Action + # @since 2.0.0 + # @api private def initialize(fs:, inflector:) @fs = fs @inflector = inflector end # rubocop:disable Layout/LineLength + + # @since 2.0.0 + # @api private def call(app, controller, action, url, http, format, skip_view, slice, context: ActionContext.new(inflector, app, slice, controller, action)) if slice generate_for_slice(controller, action, url, http, format, skip_view, slice, context) else generate_for_app(controller, action, url, http, format, skip_view, context) end end + # rubocop:enable Layout/LineLength private ROUTE_HTTP_METHODS = %w[get post delete put patch trace options link unlink].freeze @@ -60,11 +66,11 @@ attr_reader :inflector def generate_for_slice(controller, action, url, http, _format, _skip_view, slice, context) slice_directory = fs.join("slices", slice) - raise ArgumentError.new("slice not found `#{slice}'") unless fs.directory?(slice_directory) + 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) @@ -130,10 +136,10 @@ def route_http(action, http) result = (http ||= ROUTE_RESTFUL_HTTP_METHODS.fetch(action, ROUTE_DEFAULT_HTTP_METHOD)).downcase unless ROUTE_HTTP_METHODS.include?(result) - raise ArgumentError.new("unknown HTTP method: `#{http}'") + raise UnknownHTTPMethodError.new(http) end result end end