Class: Hanami::CLI::Generators::Context Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/cli/generators/context.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

Constant Summary collapse

ESBUILD_NPM_REQUIREMENT =

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

Minimum esbuild version. Keep this in with the hanami-assets peer dependency.

Since:

  • 2.0.0

"^0.28.1"

Instance Method Summary collapse

Constructor Details

#initialize(inflector, app, **options) ⇒ Context

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 Context.

Since:

  • 2.0.0



10
11
12
13
14
# File 'lib/hanami/cli/generators/context.rb', line 10

def initialize(inflector, app, **options)
  @inflector = inflector
  @app = app
  @options = options
end

Instance Method Details

#bundled_assets?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



123
124
125
# File 'lib/hanami/cli/generators/context.rb', line 123

def bundled_assets?
  Hanami.bundled?("hanami-assets")
end

#bundled_dry_monads?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



127
128
129
# File 'lib/hanami/cli/generators/context.rb', line 127

def bundled_dry_monads?
  Hanami.bundled?("dry-monads")
end

#bundled_views?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



119
120
121
# File 'lib/hanami/cli/generators/context.rb', line 119

def bundled_views?
  Hanami.bundled?("hanami-view")
end

#camelized_app_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



51
52
53
# File 'lib/hanami/cli/generators/context.rb', line 51

def camelized_app_name
  inflector.camelize(app).gsub(/[^\p{Alnum}]/, "")
end

#ctxObject

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



16
17
18
# File 'lib/hanami/cli/generators/context.rb', line 16

def ctx
  binding
end

#database_urlObject

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



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/hanami/cli/generators/context.rb', line 107

def database_url
  if generate_sqlite?
    "sqlite://db/#{app}.sqlite"
  elsif generate_postgres?
    "postgres://localhost/#{app}"
  elsif generate_mysql?
    "mysql2://root@localhost/#{app}"
  else
    raise "Unknown database option: #{database_option}"
  end
end

#esbuild_npm_packageObject

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



47
48
49
# File 'lib/hanami/cli/generators/context.rb', line 47

def esbuild_npm_package
  %("esbuild": "#{ESBUILD_NPM_REQUIREMENT}")
end

#gem_coop?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



74
75
76
77
# File 'lib/hanami/cli/generators/context.rb', line 74

def gem_coop?
  value = options.fetch(:gem_source)
  value.match? %r{(\A\w+://)?gem.coop}
end

#gem_sourceObject

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



67
68
69
70
71
72
# File 'lib/hanami/cli/generators/context.rb', line 67

def gem_source
  value = options.fetch(:gem_source)
  return value if value.match? %r{\A\w+://}

  "https://#{value}"
end

#generate_assets?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



79
80
81
# File 'lib/hanami/cli/generators/context.rb', line 79

def generate_assets?
  !options.fetch(:skip_assets, false)
end

#generate_db?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



83
84
85
# File 'lib/hanami/cli/generators/context.rb', line 83

def generate_db?
  !options.fetch(:skip_db, false)
end

#generate_mailer?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



91
92
93
# File 'lib/hanami/cli/generators/context.rb', line 91

def generate_mailer?
  !options.fetch(:skip_mailer, false)
end

#generate_minitest?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



144
145
146
# File 'lib/hanami/cli/generators/context.rb', line 144

def generate_minitest?
  test_framework_option == "minitest"
end

#generate_mysql?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



103
104
105
# File 'lib/hanami/cli/generators/context.rb', line 103

def generate_mysql?
  generate_db? && database_option == Commands::Gem::New::DATABASE_MYSQL
end

#generate_postgres?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



99
100
101
# File 'lib/hanami/cli/generators/context.rb', line 99

def generate_postgres?
  generate_db? && database_option == Commands::Gem::New::DATABASE_POSTGRES
end

#generate_rspec?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



140
141
142
# File 'lib/hanami/cli/generators/context.rb', line 140

def generate_rspec?
  test_framework_option == "rspec"
end

#generate_sqlite?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



95
96
97
# File 'lib/hanami/cli/generators/context.rb', line 95

def generate_sqlite?
  generate_db? && database_option == Commands::Gem::New::DATABASE_SQLITE
end

#generate_view?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



87
88
89
# File 'lib/hanami/cli/generators/context.rb', line 87

def generate_view?
  !options.fetch(:skip_view, false)
end

#hanami_assets_npm_packageObject

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



39
40
41
42
43
44
45
# File 'lib/hanami/cli/generators/context.rb', line 39

def hanami_assets_npm_package
  if hanami_head?
    %("hanami-assets": "hanami/assets-js#main")
  else
    %("hanami-assets": "#{Version.npm_package_requirement}")
  end
end

#hanami_gem(name) ⇒ 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



20
21
22
23
24
# File 'lib/hanami/cli/generators/context.rb', line 20

def hanami_gem(name)
  gem_name = name == "hanami" ? "hanami" : "hanami-#{name}"

  %(gem "#{gem_name}", #{hanami_gem_version(name)})
end

#hanami_gem_version(name) ⇒ 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



26
27
28
29
30
31
32
33
34
# File 'lib/hanami/cli/generators/context.rb', line 26

def hanami_gem_version(name)
  gem_name = name == "hanami" ? "hanami" : "hanami-#{name}"

  if hanami_head?
    %(github: "hanami/#{gem_name}", branch: "main")
  else
    %("#{Version.gem_requirement}")
  end
end

#hanami_head?Boolean

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:

  • (Boolean)

Since:

  • 2.0.0



63
64
65
# File 'lib/hanami/cli/generators/context.rb', line 63

def hanami_head?
  options.fetch(:head)
end

#humanized_app_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



59
60
61
# File 'lib/hanami/cli/generators/context.rb', line 59

def humanized_app_name
  inflector.humanize(app)
end

#ruby_omit_hash_values?Boolean

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.



132
133
134
# File 'lib/hanami/cli/generators/context.rb', line 132

def ruby_omit_hash_values?
  RUBY_VERSION >= "3.1"
end

#template_engineObject

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



136
137
138
# File 'lib/hanami/cli/generators/context.rb', line 136

def template_engine
  options.fetch(:template_engine)
end

#underscored_app_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



55
56
57
# File 'lib/hanami/cli/generators/context.rb', line 55

def underscored_app_name
  inflector.underscore(app)
end