From a93cfaff81f339ad5a4ca1ffb2ccf0ce8fb92fc1 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Fri, 3 Jan 2025 18:03:53 -0700 Subject: [PATCH] Clean up --- lib/hanami/cli/generators/app/ruby_class_file.rb | 12 +++++++++++- lib/hanami/cli/generators/app/view.rb | 13 +++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/hanami/cli/generators/app/ruby_class_file.rb b/lib/hanami/cli/generators/app/ruby_class_file.rb index f99eabc7..cccb75af 100644 --- a/lib/hanami/cli/generators/app/ruby_class_file.rb +++ b/lib/hanami/cli/generators/app/ruby_class_file.rb @@ -6,6 +6,8 @@ module Hanami module CLI module Generators module App + # @since 2.2.2 + # @api private class RubyClassFile def initialize( fs:, @@ -27,16 +29,24 @@ def initialize( @body = body end + # @since 2.2.2 + # @api private def create fs.create(path, file_contents) end + # @since 2.2.2 + # @api private def write fs.write(path, file_contents) end + # @since 2.2.2 + # @api private def fully_qualified_name - inflector.camelize([namespace, extra_namespace, *key.split(KEY_SEPARATOR)].join("/")) + inflector.camelize( + [namespace, extra_namespace, *key.split(KEY_SEPARATOR)].join("/"), + ) end private diff --git a/lib/hanami/cli/generators/app/view.rb b/lib/hanami/cli/generators/app/view.rb index cff60300..d0a0ac0e 100644 --- a/lib/hanami/cli/generators/app/view.rb +++ b/lib/hanami/cli/generators/app/view.rb @@ -28,10 +28,11 @@ def initialize(fs:, inflector:, out: $stdout) # @since 2.0.0 # @api private def call(key:, namespace:, base_path:) - view_class = view_class_file(key:, namespace:, base_path:) - view_class.create - view_class_name = view_class.fully_qualified_name - write_template_file(key:, namespace:, base_path:, view_class_name:) + view_class_file(key:, namespace:, base_path:).then do |view_class| + view_class.create + view_class_name = view_class.fully_qualified_name + write_template_file(key:, namespace:, base_path:, view_class_name:) + end end private @@ -52,8 +53,8 @@ def view_class_file(key:, namespace:, base_path:) def write_template_file(key:, namespace:, base_path:, view_class_name:) key_parts = key.split(KEY_SEPARATOR) - class_name_from_key = key_parts.pop - module_names_from_key = key_parts # Now that the class name has popped off + class_name_from_key = key_parts.pop # takes last segment as the class name + module_names_from_key = key_parts # the rest of the segments are the module names file_path = fs.join( base_path,