hanami 1.3.1 → 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +110 -6
- data/FEATURES.md +9 -1
- data/LICENSE.md +1 -1
- data/README.md +4 -5
- data/hanami.gemspec +26 -30
- data/lib/hanami.rb +40 -243
- data/lib/hanami/application.rb +338 -174
- data/lib/hanami/application/autoloader/inflector_adapter.rb +22 -0
- data/lib/hanami/application/container/boot/inflector.rb +7 -0
- data/lib/hanami/application/container/boot/logger.rb +8 -0
- data/lib/hanami/application/container/boot/rack_logger.rb +19 -0
- data/lib/hanami/application/container/boot/rack_monitor.rb +12 -0
- data/lib/hanami/application/container/boot/settings.rb +7 -0
- data/lib/hanami/application/router.rb +59 -0
- data/lib/hanami/application/routing/middleware/stack.rb +89 -0
- data/lib/hanami/application/routing/resolver.rb +82 -0
- data/lib/hanami/application/routing/resolver/node.rb +50 -0
- data/lib/hanami/application/routing/resolver/trie.rb +59 -0
- data/lib/hanami/application/settings.rb +23 -0
- data/lib/hanami/application/settings/definition.rb +26 -0
- data/lib/hanami/application/settings/loader.rb +97 -0
- data/lib/hanami/application/settings/struct.rb +65 -0
- data/lib/hanami/boot.rb +5 -0
- data/lib/hanami/cli/application/cli.rb +40 -0
- data/lib/hanami/cli/application/command.rb +47 -0
- data/lib/hanami/cli/application/commands.rb +16 -0
- data/lib/hanami/cli/application/commands/console.rb +81 -0
- data/lib/hanami/cli/base_command.rb +48 -0
- data/lib/hanami/cli/commands.rb +6 -42
- data/lib/hanami/cli/commands/command.rb +20 -30
- data/lib/hanami/cli/commands/server.rb +63 -14
- data/lib/hanami/configuration.rb +248 -190
- data/lib/hanami/configuration/middleware.rb +8 -28
- data/lib/hanami/configuration/router.rb +50 -0
- data/lib/hanami/configuration/sessions.rb +50 -0
- data/lib/hanami/init.rb +5 -0
- data/lib/hanami/server.rb +5 -69
- data/lib/hanami/setup.rb +8 -2
- data/lib/hanami/slice.rb +138 -0
- data/lib/hanami/version.rb +3 -1
- data/lib/hanami/web/rack_logger.rb +96 -0
- metadata +84 -228
- data/bin/hanami +0 -6
- data/lib/hanami/action/csrf_protection.rb +0 -211
- data/lib/hanami/action/routing_helpers.rb +0 -40
- data/lib/hanami/app.rb +0 -96
- data/lib/hanami/application_configuration.rb +0 -1495
- data/lib/hanami/application_name.rb +0 -108
- data/lib/hanami/application_namespace.rb +0 -14
- data/lib/hanami/assets/asset.rb +0 -72
- data/lib/hanami/assets/static.rb +0 -102
- data/lib/hanami/cli/commands/assets.rb +0 -16
- data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
- data/lib/hanami/cli/commands/console.rb +0 -95
- data/lib/hanami/cli/commands/db.rb +0 -32
- data/lib/hanami/cli/commands/db/apply.rb +0 -32
- data/lib/hanami/cli/commands/db/console.rb +0 -44
- data/lib/hanami/cli/commands/db/create.rb +0 -32
- data/lib/hanami/cli/commands/db/drop.rb +0 -32
- data/lib/hanami/cli/commands/db/migrate.rb +0 -39
- data/lib/hanami/cli/commands/db/prepare.rb +0 -32
- data/lib/hanami/cli/commands/db/rollback.rb +0 -59
- data/lib/hanami/cli/commands/db/version.rb +0 -32
- data/lib/hanami/cli/commands/destroy.rb +0 -26
- data/lib/hanami/cli/commands/destroy/action.rb +0 -137
- data/lib/hanami/cli/commands/destroy/app.rb +0 -159
- data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
- data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
- data/lib/hanami/cli/commands/destroy/model.rb +0 -84
- data/lib/hanami/cli/commands/generate.rb +0 -28
- data/lib/hanami/cli/commands/generate/action.rb +0 -321
- data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
- data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
- data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
- data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/app.rb +0 -243
- data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
- data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
- data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
- data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
- data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
- data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
- data/lib/hanami/cli/commands/generate/migration.rb +0 -41
- data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
- data/lib/hanami/cli/commands/generate/model.rb +0 -125
- data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
- data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
- data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/secret.rb +0 -48
- data/lib/hanami/cli/commands/new.rb +0 -578
- data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
- data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
- data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/new/Gemfile.erb +0 -58
- data/lib/hanami/cli/commands/new/README.md.erb +0 -33
- data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
- data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
- data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
- data/lib/hanami/cli/commands/new/gitignore.erb +0 -2
- data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -3
- data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
- data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
- data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
- data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
- data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
- data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
- data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
- data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
- data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
- data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
- data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
- data/lib/hanami/cli/commands/project.rb +0 -421
- data/lib/hanami/cli/commands/routes.rb +0 -21
- data/lib/hanami/cli/commands/templates.rb +0 -31
- data/lib/hanami/cli/commands/version.rb +0 -19
- data/lib/hanami/common_logger.rb +0 -93
- data/lib/hanami/components.rb +0 -156
- data/lib/hanami/components/app/assets.rb +0 -59
- data/lib/hanami/components/app/controller.rb +0 -74
- data/lib/hanami/components/app/routes.rb +0 -59
- data/lib/hanami/components/app/view.rb +0 -44
- data/lib/hanami/components/component.rb +0 -182
- data/lib/hanami/components/components.rb +0 -479
- data/lib/hanami/components/routes_inspector.rb +0 -72
- data/lib/hanami/config/cookies.rb +0 -69
- data/lib/hanami/config/framework_configuration.rb +0 -43
- data/lib/hanami/config/load_paths.rb +0 -46
- data/lib/hanami/config/mapper.rb +0 -47
- data/lib/hanami/config/routes.rb +0 -20
- data/lib/hanami/config/security.rb +0 -110
- data/lib/hanami/config/sessions.rb +0 -103
- data/lib/hanami/configuration/app.rb +0 -18
- data/lib/hanami/early_hints.rb +0 -129
- data/lib/hanami/env.rb +0 -69
- data/lib/hanami/environment.rb +0 -513
- data/lib/hanami/environment_application_configurations.rb +0 -37
- data/lib/hanami/frameworks.rb +0 -22
- data/lib/hanami/hanamirc.rb +0 -169
- data/lib/hanami/mailer/glue.rb +0 -27
- data/lib/hanami/middleware_stack.rb +0 -172
- data/lib/hanami/rake_helper.rb +0 -78
- data/lib/hanami/rake_tasks.rb +0 -2
- data/lib/hanami/rendering_policy.rb +0 -95
- data/lib/hanami/routes.rb +0 -219
- data/lib/hanami/routing/default.rb +0 -32
- data/lib/hanami/static.rb +0 -63
- data/lib/hanami/templates/default.html.erb +0 -30
- data/lib/hanami/templates/welcome.html.erb +0 -52
- data/lib/hanami/views/default.rb +0 -37
- data/lib/hanami/views/default_template_finder.rb +0 -22
- data/lib/hanami/views/null_view.rb +0 -15
- data/lib/hanami/welcome.rb +0 -36
@@ -1,32 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
# Hanami CLI
|
3
|
-
#
|
4
|
-
# @since 1.1.0
|
5
|
-
class CLI
|
6
|
-
module Commands
|
7
|
-
# @since 1.1.0
|
8
|
-
# @api private
|
9
|
-
module Db
|
10
|
-
require "hanami/cli/commands/db/version"
|
11
|
-
require "hanami/cli/commands/db/create"
|
12
|
-
require "hanami/cli/commands/db/drop"
|
13
|
-
require "hanami/cli/commands/db/migrate"
|
14
|
-
require "hanami/cli/commands/db/rollback"
|
15
|
-
require "hanami/cli/commands/db/prepare"
|
16
|
-
require "hanami/cli/commands/db/apply"
|
17
|
-
require "hanami/cli/commands/db/console"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
register "db" do |prefix|
|
22
|
-
prefix.register "version", Commands::Db::Version
|
23
|
-
prefix.register "create", Commands::Db::Create
|
24
|
-
prefix.register "drop", Commands::Db::Drop
|
25
|
-
prefix.register "migrate", Commands::Db::Migrate
|
26
|
-
prefix.register "rollback", Commands::Db::Rollback
|
27
|
-
prefix.register "prepare", Commands::Db::Prepare
|
28
|
-
prefix.register "apply", Commands::Db::Apply
|
29
|
-
prefix.register "console", Commands::Db::Console
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Db
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Apply < Command
|
8
|
-
requires "model.sql"
|
9
|
-
|
10
|
-
desc "Migrate, dump the SQL schema, and delete the migrations (experimental)"
|
11
|
-
|
12
|
-
# @since 1.1.0
|
13
|
-
# @api private
|
14
|
-
def call(**options)
|
15
|
-
context = Context.new(options: options)
|
16
|
-
|
17
|
-
apply_migrations(context)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# @since 1.1.0
|
23
|
-
# @api private
|
24
|
-
def apply_migrations(*)
|
25
|
-
require "hanami/model/migrator"
|
26
|
-
Hanami::Model::Migrator.apply
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Db
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Console < Command
|
8
|
-
requires 'model.sql'
|
9
|
-
|
10
|
-
desc "Starts a database console"
|
11
|
-
|
12
|
-
# @since 1.1.0
|
13
|
-
# @api private
|
14
|
-
def call(**options)
|
15
|
-
context = Context.new(options: options)
|
16
|
-
|
17
|
-
start_console(context)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# @since 1.1.0
|
23
|
-
# @api private
|
24
|
-
def start_console(*)
|
25
|
-
exec console.connection_string
|
26
|
-
end
|
27
|
-
|
28
|
-
# @since 1.1.0
|
29
|
-
# @api private
|
30
|
-
def configuration_url
|
31
|
-
Hanami::Components['model.configuration'].url
|
32
|
-
end
|
33
|
-
|
34
|
-
# @since 1.1.0
|
35
|
-
# @api private
|
36
|
-
def console
|
37
|
-
require "hanami/model/sql/console"
|
38
|
-
Hanami::Model::Sql::Console.new(configuration_url)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Db
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Create < Command
|
8
|
-
requires "model.configuration"
|
9
|
-
|
10
|
-
desc "Create the database (only for development/test)"
|
11
|
-
|
12
|
-
# @since 1.1.0
|
13
|
-
# @api private
|
14
|
-
def call(**options)
|
15
|
-
context = Context.new(options: options)
|
16
|
-
|
17
|
-
create_database(context)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# @since 1.1.0
|
23
|
-
# @api private
|
24
|
-
def create_database(*)
|
25
|
-
require "hanami/model/migrator"
|
26
|
-
Hanami::Model::Migrator.create
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
# @since 1.1.0
|
5
|
-
# @api private
|
6
|
-
module Db
|
7
|
-
class Drop < Command
|
8
|
-
requires "model.configuration"
|
9
|
-
|
10
|
-
desc "Drop the database (only for development/test)"
|
11
|
-
|
12
|
-
# @since 1.1.0
|
13
|
-
# @api private
|
14
|
-
def call(**options)
|
15
|
-
context = Context.new(options: options)
|
16
|
-
|
17
|
-
drop_database(context)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# @since 1.1.0
|
23
|
-
# @api private
|
24
|
-
def drop_database(*)
|
25
|
-
require "hanami/model/migrator"
|
26
|
-
Hanami::Model::Migrator.drop
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Db
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Migrate < Command
|
8
|
-
requires "model.sql"
|
9
|
-
|
10
|
-
desc "Migrate the database"
|
11
|
-
|
12
|
-
argument :version, desc: "The target version of the migration (see `hanami db version`)"
|
13
|
-
|
14
|
-
example [
|
15
|
-
" # Migrate to the last version",
|
16
|
-
"#{Project.migration_timestamp} # Migrate to a specific version"
|
17
|
-
]
|
18
|
-
|
19
|
-
# @since 1.1.0
|
20
|
-
# @api private
|
21
|
-
def call(version: nil, **options)
|
22
|
-
context = Context.new(version: version, options: options)
|
23
|
-
|
24
|
-
migrate_database(context)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
# @since 1.1.0
|
30
|
-
# @api private
|
31
|
-
def migrate_database(context)
|
32
|
-
require "hanami/model/migrator"
|
33
|
-
Hanami::Model::Migrator.migrate(version: context.version)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Db
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Prepare < Command
|
8
|
-
requires "model.sql"
|
9
|
-
|
10
|
-
desc "Drop, create, and migrate the database (only for development/test)"
|
11
|
-
|
12
|
-
# @since 1.1.0
|
13
|
-
# @api private
|
14
|
-
def call(**options)
|
15
|
-
context = Context.new(options: options)
|
16
|
-
|
17
|
-
prepare_database(context)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# @since 1.1.0
|
23
|
-
# @api private
|
24
|
-
def prepare_database(*)
|
25
|
-
require 'hanami/model/migrator'
|
26
|
-
Hanami::Model::Migrator.prepare
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require "hanami/utils/kernel"
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
class CLI
|
5
|
-
module Commands
|
6
|
-
module Db
|
7
|
-
# @since 1.1.0
|
8
|
-
# @api private
|
9
|
-
class Rollback < Command
|
10
|
-
requires "model.sql"
|
11
|
-
|
12
|
-
desc "Rollback migrations"
|
13
|
-
|
14
|
-
argument :steps, desc: "Number of steps to rollback the database", default: 1
|
15
|
-
|
16
|
-
example [
|
17
|
-
" # Rollbacks latest migration",
|
18
|
-
"2 # Rollbacks last two migrations"
|
19
|
-
]
|
20
|
-
|
21
|
-
# @since 1.1.0
|
22
|
-
# @api private
|
23
|
-
def call(steps:, **)
|
24
|
-
context = Context.new(steps: steps)
|
25
|
-
context = assert_valid_steps!(context)
|
26
|
-
|
27
|
-
rollback_database(context)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
# @since 1.1.0
|
33
|
-
# @api private
|
34
|
-
def assert_valid_steps!(context)
|
35
|
-
context = context.with(steps: Utils::Kernel.Integer(context.steps.to_s))
|
36
|
-
handle_error(context) unless context.steps.positive?
|
37
|
-
context
|
38
|
-
rescue TypeError
|
39
|
-
handle_error(context)
|
40
|
-
end
|
41
|
-
|
42
|
-
# @since 1.1.0
|
43
|
-
# @api private
|
44
|
-
def rollback_database(context)
|
45
|
-
require "hanami/model/migrator"
|
46
|
-
Hanami::Model::Migrator.rollback(steps: context.steps)
|
47
|
-
end
|
48
|
-
|
49
|
-
# @since 1.1.0
|
50
|
-
# @api private
|
51
|
-
def handle_error(context)
|
52
|
-
warn "the number of steps must be a positive integer (you entered `#{context.steps}')."
|
53
|
-
exit(1)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Db
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Version < Command
|
8
|
-
requires "model.configuration.no_logger"
|
9
|
-
|
10
|
-
desc "Print the current migrated version"
|
11
|
-
|
12
|
-
# @since 1.1.0
|
13
|
-
# @api private
|
14
|
-
def call(**options)
|
15
|
-
context = Context.new(options: options)
|
16
|
-
|
17
|
-
print_database_version(context)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# @since 1.1.0
|
23
|
-
# @api private
|
24
|
-
def print_database_version(*)
|
25
|
-
require "hanami/model/migrator"
|
26
|
-
puts Hanami::Model::Migrator.version
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
# Hanami CLI
|
3
|
-
#
|
4
|
-
# @since 1.1.0
|
5
|
-
class CLI
|
6
|
-
module Commands
|
7
|
-
# @since 1.1.0
|
8
|
-
# @api private
|
9
|
-
module Destroy
|
10
|
-
require "hanami/cli/commands/destroy/app"
|
11
|
-
require "hanami/cli/commands/destroy/action"
|
12
|
-
require "hanami/cli/commands/destroy/model"
|
13
|
-
require "hanami/cli/commands/destroy/mailer"
|
14
|
-
require "hanami/cli/commands/destroy/migration"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
register "destroy", aliases: ["d"] do |prefix|
|
19
|
-
prefix.register "app", Commands::Destroy::App
|
20
|
-
prefix.register "action", Commands::Destroy::Action
|
21
|
-
prefix.register "model", Commands::Destroy::Model
|
22
|
-
prefix.register "mailer", Commands::Destroy::Mailer
|
23
|
-
prefix.register "migration", Commands::Destroy::Migration
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Destroy
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Action < Command
|
8
|
-
desc "Destroy an action from app"
|
9
|
-
|
10
|
-
example [
|
11
|
-
"web home#index # Basic usage",
|
12
|
-
"admin users#index # Destroy from `admin` app"
|
13
|
-
]
|
14
|
-
|
15
|
-
argument :app, required: true, desc: "The application name (eg. `web`)"
|
16
|
-
argument :action, required: true, desc: "The action name (eg. `home#index`)"
|
17
|
-
|
18
|
-
# @since 1.1.0
|
19
|
-
# @api private
|
20
|
-
def call(app:, action:, **options)
|
21
|
-
app = Utils::String.underscore(app)
|
22
|
-
*controller, action = controller_and_action(action)
|
23
|
-
action_name = controller_and_action_name(controller, action)
|
24
|
-
|
25
|
-
context = Context.new(app: app, controller: controller, action: action, action_name: action_name, options: options)
|
26
|
-
|
27
|
-
assert_valid_app!(context)
|
28
|
-
|
29
|
-
remove_route(context)
|
30
|
-
destroy_view_spec(context)
|
31
|
-
destroy_action_spec(context)
|
32
|
-
destroy_templates(context)
|
33
|
-
destroy_view(context)
|
34
|
-
destroy_action(context)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
# @since 1.1.0
|
40
|
-
# @api private
|
41
|
-
def assert_valid_app!(context)
|
42
|
-
return if project.app?(context)
|
43
|
-
|
44
|
-
existing_apps = project.apps.map { |name| "`#{name}'" }.join(' ')
|
45
|
-
warn "`#{context.app}' is not a valid APP. Please specify one of: #{existing_apps}"
|
46
|
-
exit(1)
|
47
|
-
end
|
48
|
-
|
49
|
-
# @since 1.1.0
|
50
|
-
# @api private
|
51
|
-
def controller_and_action(name)
|
52
|
-
# FIXME: extract this regexp
|
53
|
-
name.split(/#|\//)
|
54
|
-
end
|
55
|
-
|
56
|
-
# @since 1.1.0
|
57
|
-
# @api private
|
58
|
-
def controller_and_action_name(controller, action)
|
59
|
-
# FIXME: extract this separator
|
60
|
-
[namespaced_controller(controller), action].join("#")
|
61
|
-
end
|
62
|
-
|
63
|
-
# @since 1.1.0
|
64
|
-
# #api private
|
65
|
-
def namespaced_controller(controller)
|
66
|
-
controller.join("/")
|
67
|
-
end
|
68
|
-
|
69
|
-
# @since 1.1.0
|
70
|
-
# @api private
|
71
|
-
def remove_route(context)
|
72
|
-
content = %r{#{context.action_name}}
|
73
|
-
destination = project.app_routes(context)
|
74
|
-
|
75
|
-
begin
|
76
|
-
files.remove_line(destination, content)
|
77
|
-
rescue ArgumentError
|
78
|
-
warn "cannot find `#{context.action_name}' in `#{context.app}' application."
|
79
|
-
warn "please run `hanami routes' to know the existing actions."
|
80
|
-
exit(1)
|
81
|
-
end
|
82
|
-
|
83
|
-
say(:subtract, destination)
|
84
|
-
end
|
85
|
-
|
86
|
-
# @since 1.1.0
|
87
|
-
# @api private
|
88
|
-
def destroy_view_spec(context)
|
89
|
-
destination = project.view_spec(context)
|
90
|
-
return unless files.exist?(destination)
|
91
|
-
|
92
|
-
files.delete(destination)
|
93
|
-
say(:remove, destination)
|
94
|
-
end
|
95
|
-
|
96
|
-
# @since 1.1.0
|
97
|
-
# @api private
|
98
|
-
def destroy_action_spec(context)
|
99
|
-
destination = project.action_spec(context)
|
100
|
-
|
101
|
-
files.delete(destination)
|
102
|
-
say(:remove, destination)
|
103
|
-
end
|
104
|
-
|
105
|
-
# @since 1.1.0
|
106
|
-
# @api private
|
107
|
-
def destroy_templates(context)
|
108
|
-
destinations = project.templates(context)
|
109
|
-
destinations.each do |destination|
|
110
|
-
files.delete(destination)
|
111
|
-
say(:remove, destination)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# @since 1.1.0
|
116
|
-
# @api private
|
117
|
-
def destroy_view(context)
|
118
|
-
destination = project.view(context)
|
119
|
-
return unless files.exist?(destination)
|
120
|
-
|
121
|
-
files.delete(destination)
|
122
|
-
say(:remove, destination)
|
123
|
-
end
|
124
|
-
|
125
|
-
# @since 1.1.0
|
126
|
-
# @api private
|
127
|
-
def destroy_action(context)
|
128
|
-
destination = project.action(context)
|
129
|
-
|
130
|
-
files.delete(destination)
|
131
|
-
say(:remove, destination)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|