Class: Hanami::CLI::Generators::App::RubyFile Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/cli/generators/app/ruby_file.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

Direct Known Subclasses

RubyClassFile, RubyModuleFile

Instance Method Summary collapse

Constructor Details

#initialize(fs:, inflector:, key:, namespace:, base_path:, extra_namespace: nil, auto_register: nil, body: [], **_opts) ⇒ RubyFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RubyFile.

Since:

  • 2.0.0



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 11

def initialize(
  fs:,
  inflector:,
  key:,
  namespace:,
  base_path:,
  extra_namespace: nil,
  auto_register: nil,
  body: [],
  **_opts
)
  @fs = fs
  @inflector = inflector
  @key_segments = key.split(KEY_SEPARATOR).map { |segment| inflector.underscore(segment) }
  @namespace = namespace
  @base_path = base_path
  @extra_namespace = extra_namespace&.downcase
  @auto_register = auto_register
  @body = body
end

Instance Method Details

#createObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



33
34
35
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 33

def create
  fs.create(path, file_contents)
end

#fully_qualified_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



43
44
45
46
47
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 43

def fully_qualified_name
  inflector.camelize(
    [namespace, extra_namespace, *key_segments].join("/"),
  )
end

#pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



50
51
52
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 50

def path
  fs.join(directory, "#{key_segments.last}.rb")
end

#writeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



38
39
40
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 38

def write
  fs.write(path, file_contents)
end