Class: Hanami::CLI::Generators::Context Private
- Inherits:
-
Object
- Object
- Hanami::CLI::Generators::Context
- 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.
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.
"^0.28.1"
Instance Method Summary collapse
- #bundled_assets? ⇒ Boolean private
- #bundled_dry_monads? ⇒ Boolean private
- #bundled_views? ⇒ Boolean private
- #camelized_app_name ⇒ Object private
- #ctx ⇒ Object private
- #database_url ⇒ Object private
- #esbuild_npm_package ⇒ Object private
- #gem_coop? ⇒ Boolean private
- #gem_source ⇒ Object private
- #generate_assets? ⇒ Boolean private
- #generate_db? ⇒ Boolean private
- #generate_mailer? ⇒ Boolean private
- #generate_minitest? ⇒ Boolean private
- #generate_mysql? ⇒ Boolean private
- #generate_postgres? ⇒ Boolean private
- #generate_rspec? ⇒ Boolean private
- #generate_sqlite? ⇒ Boolean private
- #generate_view? ⇒ Boolean private
- #hanami_assets_npm_package ⇒ Object private
- #hanami_gem(name) ⇒ Object private
- #hanami_gem_version(name) ⇒ Object private
- #hanami_head? ⇒ Boolean private
- #humanized_app_name ⇒ Object private
-
#initialize(inflector, app, **options) ⇒ Context
constructor
private
A new instance of Context.
- #ruby_omit_hash_values? ⇒ Boolean private
- #template_engine ⇒ Object private
- #underscored_app_name ⇒ Object private
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.
10 11 12 13 14 |
# File 'lib/hanami/cli/generators/context.rb', line 10 def initialize(inflector, app, **) @inflector = inflector @app = app @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.
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.
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.
119 120 121 |
# File 'lib/hanami/cli/generators/context.rb', line 119 def bundled_views? Hanami.bundled?("hanami-view") end |
#camelized_app_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.
51 52 53 |
# File 'lib/hanami/cli/generators/context.rb', line 51 def camelized_app_name inflector.camelize(app).gsub(/[^\p{Alnum}]/, "") end |
#ctx ⇒ 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.
16 17 18 |
# File 'lib/hanami/cli/generators/context.rb', line 16 def ctx binding end |
#database_url ⇒ 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.
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_package ⇒ 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.
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.
74 75 76 77 |
# File 'lib/hanami/cli/generators/context.rb', line 74 def gem_coop? value = .fetch(:gem_source) value.match? %r{(\A\w+://)?gem.coop} end |
#gem_source ⇒ 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.
67 68 69 70 71 72 |
# File 'lib/hanami/cli/generators/context.rb', line 67 def gem_source value = .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.
79 80 81 |
# File 'lib/hanami/cli/generators/context.rb', line 79 def generate_assets? !.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.
83 84 85 |
# File 'lib/hanami/cli/generators/context.rb', line 83 def generate_db? !.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.
91 92 93 |
# File 'lib/hanami/cli/generators/context.rb', line 91 def generate_mailer? !.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.
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.
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.
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.
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.
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.
87 88 89 |
# File 'lib/hanami/cli/generators/context.rb', line 87 def generate_view? !.fetch(:skip_view, false) end |
#hanami_assets_npm_package ⇒ 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.
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.
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.
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.
63 64 65 |
# File 'lib/hanami/cli/generators/context.rb', line 63 def hanami_head? .fetch(:head) end |
#humanized_app_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.
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_engine ⇒ 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.
136 137 138 |
# File 'lib/hanami/cli/generators/context.rb', line 136 def template_engine .fetch(:template_engine) end |
#underscored_app_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.
55 56 57 |
# File 'lib/hanami/cli/generators/context.rb', line 55 def underscored_app_name inflector.underscore(app) end |