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

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



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

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



146
147
148
# File 'lib/hanami/cli/generators/context.rb', line 146

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



152
153
154
# File 'lib/hanami/cli/generators/context.rb', line 152

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



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

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



57
58
59
# File 'lib/hanami/cli/generators/context.rb', line 57

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



23
24
25
# File 'lib/hanami/cli/generators/context.rb', line 23

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



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/hanami/cli/generators/context.rb', line 126

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

#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.3.0



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

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



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

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



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

def generate_db?
  !options.fetch(:skip_db, false)
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.2.0



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

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



114
115
116
# File 'lib/hanami/cli/generators/context.rb', line 114

def generate_postgres?
  generate_db? && database_option == Commands::Gem::New::DATABASE_POSTGRES
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.2.0



108
109
110
# File 'lib/hanami/cli/generators/context.rb', line 108

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



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

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



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

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



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

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



35
36
37
38
39
40
41
42
43
# File 'lib/hanami/cli/generators/context.rb', line 35

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



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

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



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

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.



160
161
162
# File 'lib/hanami/cli/generators/context.rb', line 160

def ruby_omit_hash_values?
  RUBY_VERSION >= "3.1"
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



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

def underscored_app_name
  inflector.underscore(app)
end