Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cllns committed Jan 4, 2025
1 parent 9f58101 commit a93cfaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
12 changes: 11 additions & 1 deletion lib/hanami/cli/generators/app/ruby_class_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Hanami
module CLI
module Generators
module App
# @since 2.2.2
# @api private
class RubyClassFile
def initialize(
fs:,
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lib/hanami/cli/generators/app/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit a93cfaf

Please sign in to comment.