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, requires: [], 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
31
32
# 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,
  requires: [],
  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
  @requires = requires
  @body = body
end

Instance Method Details

#create(force: false) ⇒ Object

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



35
36
37
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 35

def create(force: false)
  fs.create(path, file_contents, force:)
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



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

def fully_qualified_name
  inflector.camelize(
    [namespace, extra_namespace, *key_segments].compact.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



52
53
54
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 52

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



40
41
42
# File 'lib/hanami/cli/generators/app/ruby_file.rb', line 40

def write
  fs.write(path, file_contents)
end