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.
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
- #gem_source ⇒ Object private
- #generate_assets? ⇒ Boolean private
- #generate_db? ⇒ Boolean private
- #generate_mysql? ⇒ Boolean private
- #generate_postgres? ⇒ 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
- #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.
15 16 17 18 19 |
# File 'lib/hanami/cli/generators/context.rb', line 15 def initialize(inflector, app, **) @inflector = inflector @app = app = 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.
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.
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.
140 141 142 |
# File 'lib/hanami/cli/generators/context.rb', line 140 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.
57 58 59 |
# File 'lib/hanami/cli/generators/context.rb', line 57 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.
23 24 25 |
# File 'lib/hanami/cli/generators/context.rb', line 23 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.
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_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.
81 82 83 84 85 86 |
# File 'lib/hanami/cli/generators/context.rb', line 81 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.
90 91 92 |
# File 'lib/hanami/cli/generators/context.rb', line 90 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.
96 97 98 |
# File 'lib/hanami/cli/generators/context.rb', line 96 def generate_db? !.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.
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.
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.
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.
102 103 104 |
# File 'lib/hanami/cli/generators/context.rb', line 102 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.
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.
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.
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.
75 76 77 |
# File 'lib/hanami/cli/generators/context.rb', line 75 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.
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_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.
63 64 65 |
# File 'lib/hanami/cli/generators/context.rb', line 63 def underscored_app_name inflector.underscore(app) end |