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,108 +0,0 @@
|
|
1
|
-
require 'hanami/utils/string'
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
# An application name.
|
5
|
-
#
|
6
|
-
# @since 0.2.1
|
7
|
-
# @api private
|
8
|
-
class ApplicationName
|
9
|
-
|
10
|
-
# A list of words that are prohibited from forming the application name
|
11
|
-
#
|
12
|
-
# @since 0.2.1
|
13
|
-
# @api private
|
14
|
-
RESERVED_WORDS = %w(hanami).freeze
|
15
|
-
|
16
|
-
# Initialize and check against reserved words
|
17
|
-
#
|
18
|
-
# An application name needs to be translated in quite a few ways:
|
19
|
-
# First, it must be checked against a list of reserved words and rejected
|
20
|
-
# if it is invalid. Secondly, assuming it is not invalid, it must be able
|
21
|
-
# to be output roughly as given, but with the following changes:
|
22
|
-
#
|
23
|
-
# 1. downcased,
|
24
|
-
# 2. with surrounding spaces removed,
|
25
|
-
# 3. with internal whitespace rendered as underscores
|
26
|
-
# 4. with underscores de-duplicated
|
27
|
-
#
|
28
|
-
# which is the default output. It must also be transformable into an
|
29
|
-
# environment variable.
|
30
|
-
#
|
31
|
-
# @return [Hanami::ApplicationName] a new instance of the application name
|
32
|
-
#
|
33
|
-
# @since 0.2.1
|
34
|
-
# @api private
|
35
|
-
def initialize(name)
|
36
|
-
@name = sanitize(name.to_s)
|
37
|
-
ensure_validity!
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns the cleaned application name.
|
41
|
-
#
|
42
|
-
# @return [String] the sanitized name
|
43
|
-
#
|
44
|
-
# @example
|
45
|
-
# ApplicationName.new("my-App ").to_s # => "my_app"
|
46
|
-
#
|
47
|
-
# @since 0.2.1
|
48
|
-
# @api private
|
49
|
-
def to_s
|
50
|
-
@name
|
51
|
-
end
|
52
|
-
|
53
|
-
# @api private
|
54
|
-
# @since 0.8.0
|
55
|
-
alias_method :to_str, :to_s
|
56
|
-
|
57
|
-
# Returns the application name uppercased with non-alphanumeric characters
|
58
|
-
# as underscores.
|
59
|
-
#
|
60
|
-
# @return [String] the upcased name
|
61
|
-
#
|
62
|
-
# @example
|
63
|
-
# ApplicationName.new("my-app").to_env_s => "MY_APP"
|
64
|
-
#
|
65
|
-
# @since 0.2.1
|
66
|
-
# @api private
|
67
|
-
def to_env_s
|
68
|
-
@name.upcase.gsub(/\W/, '_')
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns true if a potential application name matches one of the reserved
|
72
|
-
# words.
|
73
|
-
#
|
74
|
-
# @param name [String] the application name
|
75
|
-
# @return [TrueClass, FalseClass] the result of the check
|
76
|
-
#
|
77
|
-
# @example
|
78
|
-
# Hanami::ApplicationName.invalid?("hanami") # => true
|
79
|
-
#
|
80
|
-
# @since 0.2.1
|
81
|
-
# @api private
|
82
|
-
def self.invalid?(name)
|
83
|
-
RESERVED_WORDS.include?(name)
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
# Raises RuntimeError with explanation if the provided name is invalid.
|
89
|
-
#
|
90
|
-
# @since 0.2.1
|
91
|
-
# @api private
|
92
|
-
def ensure_validity!
|
93
|
-
if self.class.invalid?(@name)
|
94
|
-
raise RuntimeError,
|
95
|
-
"application name must not be any one of the following: " +
|
96
|
-
RESERVED_WORDS.join(", ")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# Cleans a string to be a functioning application name.
|
101
|
-
#
|
102
|
-
# @since 0.2.1
|
103
|
-
# @api private
|
104
|
-
def sanitize(name)
|
105
|
-
Utils::String.transform(name.strip, :namespace, :underscore)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/lib/hanami/assets/asset.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'hanami/utils/file_list'
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
# @api private
|
5
|
-
module Assets
|
6
|
-
# Requested asset
|
7
|
-
#
|
8
|
-
# @since 0.8.0
|
9
|
-
# @api private
|
10
|
-
class Asset
|
11
|
-
# @since 0.8.0
|
12
|
-
# @api private
|
13
|
-
PUBLIC_DIRECTORY = Hanami.public_directory.join('**', '*').to_s.freeze
|
14
|
-
|
15
|
-
# @since 0.8.0
|
16
|
-
# @api private
|
17
|
-
URL_SEPARATOR = '/'.freeze
|
18
|
-
|
19
|
-
# @since 0.8.0
|
20
|
-
# @api private
|
21
|
-
attr_reader :path
|
22
|
-
|
23
|
-
# @since 0.8.0
|
24
|
-
# @api private
|
25
|
-
attr_reader :config
|
26
|
-
|
27
|
-
# @since 0.8.0
|
28
|
-
# @api private
|
29
|
-
attr_reader :original
|
30
|
-
|
31
|
-
# @since 0.8.0
|
32
|
-
# @api private
|
33
|
-
def initialize(sources, path)
|
34
|
-
@path = path
|
35
|
-
@prefix, @config = sources.find { |p, _| path.start_with?(p) }
|
36
|
-
|
37
|
-
if @prefix && @config
|
38
|
-
@original = @config.sources.find(@path.sub(@prefix, ''))
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# @since 0.8.0
|
43
|
-
# @api private
|
44
|
-
def precompile?
|
45
|
-
original && config
|
46
|
-
end
|
47
|
-
|
48
|
-
# @since 0.8.0
|
49
|
-
# @api private
|
50
|
-
def exist?
|
51
|
-
return true unless original.nil?
|
52
|
-
|
53
|
-
file_path = path.tr(URL_SEPARATOR, ::File::SEPARATOR)
|
54
|
-
destination = find_asset do |a|
|
55
|
-
a.end_with?(file_path)
|
56
|
-
end
|
57
|
-
|
58
|
-
!destination.nil?
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
# @since 0.8.0
|
64
|
-
# @api private
|
65
|
-
def find_asset
|
66
|
-
Utils::FileList[PUBLIC_DIRECTORY].find do |asset|
|
67
|
-
yield asset unless ::File.directory?(asset)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/lib/hanami/assets/static.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'hanami/static'
|
2
|
-
require 'hanami/assets/compiler'
|
3
|
-
require 'hanami/assets/asset'
|
4
|
-
|
5
|
-
# Copyright notice
|
6
|
-
#
|
7
|
-
# This file contains a method copied from Rack::Static (rack gem).
|
8
|
-
#
|
9
|
-
# Rack - Copyright (C) 2007 Christian Neukirchen
|
10
|
-
# Released under the MIT License
|
11
|
-
|
12
|
-
module Hanami
|
13
|
-
module Assets
|
14
|
-
# Serve static assets in development environments (development, test).
|
15
|
-
#
|
16
|
-
# While serving static assets is a role delegated in production to web
|
17
|
-
# servers (like Nginx), in development it's rare to use a web server.
|
18
|
-
# For this purpose Hanami enables this Rack middleware to serve static
|
19
|
-
# assets in development (and test) phase.
|
20
|
-
#
|
21
|
-
# The other important role of `Hanami::Assets::Static` is to lazily compile
|
22
|
-
# (or copy) the assets into the public directory.
|
23
|
-
#
|
24
|
-
# @since 0.8.0
|
25
|
-
# @api private
|
26
|
-
#
|
27
|
-
# @see Hanami::Static
|
28
|
-
class Static < Hanami::Static
|
29
|
-
# @since 0.8.0
|
30
|
-
# @api private
|
31
|
-
PATH_INFO = 'PATH_INFO'.freeze
|
32
|
-
|
33
|
-
# @since 0.8.0
|
34
|
-
# @api private
|
35
|
-
def initialize(app)
|
36
|
-
super(app, header_rules: [])
|
37
|
-
@sources = _sources_from_applications
|
38
|
-
end
|
39
|
-
|
40
|
-
# @since 0.8.0
|
41
|
-
# @api private
|
42
|
-
def call(env)
|
43
|
-
asset = Assets::Asset.new(@sources, env[PATH_INFO])
|
44
|
-
|
45
|
-
if serve?(asset)
|
46
|
-
precompile(asset)
|
47
|
-
serve(env, asset)
|
48
|
-
else
|
49
|
-
@app.call(env)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
# @since 0.8.0
|
56
|
-
# @api private
|
57
|
-
def serve?(asset)
|
58
|
-
can_serve(asset.path) || asset.exist? || asset.precompile?
|
59
|
-
end
|
60
|
-
|
61
|
-
# @since 0.8.0
|
62
|
-
# @api private
|
63
|
-
def precompile(asset)
|
64
|
-
Hanami::Assets::Compiler.compile(asset.config, asset.original) if asset.precompile?
|
65
|
-
end
|
66
|
-
|
67
|
-
# Copyright notice
|
68
|
-
#
|
69
|
-
# This method is copied from Rack::Static#call
|
70
|
-
#
|
71
|
-
# Rack - Copyright (C) 2007 Christian Neukirchen
|
72
|
-
# Released under the MIT License
|
73
|
-
#
|
74
|
-
# @since 0.8.0
|
75
|
-
# @api private
|
76
|
-
#
|
77
|
-
# @see http://www.rubydoc.info/gems/rack/Rack%2FStatic%3Acall
|
78
|
-
def serve(env, asset)
|
79
|
-
path = asset.path
|
80
|
-
env[PATH_INFO] = (path =~ /\/$/ ? path + @index : @urls[path]) if overwrite_file_path(path)
|
81
|
-
path = env[PATH_INFO]
|
82
|
-
response = @file_server.call(env)
|
83
|
-
|
84
|
-
headers = response[1]
|
85
|
-
applicable_rules(path).each do |_, new_headers|
|
86
|
-
new_headers.each { |field, content| headers[field] = content }
|
87
|
-
end
|
88
|
-
|
89
|
-
response
|
90
|
-
end
|
91
|
-
|
92
|
-
# @since 0.8.0
|
93
|
-
# @api private
|
94
|
-
def _sources_from_applications
|
95
|
-
Hanami::Components.resolve('apps.assets.configurations')
|
96
|
-
Hanami::Components['apps.assets.configurations'].each_with_object({}) do |config, result|
|
97
|
-
result["#{config.prefix}/"] = config
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,16 +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 Assets
|
10
|
-
require "hanami/cli/commands/assets/precompile"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
register "assets precompile", Commands::Assets::Precompile
|
15
|
-
end
|
16
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
module Assets
|
5
|
-
# @since 1.1.0
|
6
|
-
# @api private
|
7
|
-
class Precompile < Command
|
8
|
-
requires "apps.assets.configurations"
|
9
|
-
|
10
|
-
desc "Precompile assets for deployment"
|
11
|
-
|
12
|
-
example [
|
13
|
-
" # Basic usage",
|
14
|
-
"HANAMI_ENV=production # Precompile assets for production environment"
|
15
|
-
]
|
16
|
-
|
17
|
-
# @since 1.1.0
|
18
|
-
# @api private
|
19
|
-
def call(**options)
|
20
|
-
context = Context.new(options: options)
|
21
|
-
|
22
|
-
precompile_assets(context)
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
# @since 1.1.0
|
28
|
-
# @api private
|
29
|
-
def precompile_assets(*)
|
30
|
-
Hanami::Assets.precompile(configurations)
|
31
|
-
end
|
32
|
-
|
33
|
-
# @since 1.1.0
|
34
|
-
# @api private
|
35
|
-
def configurations
|
36
|
-
requirements['apps.assets.configurations']
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
class CLI
|
3
|
-
module Commands
|
4
|
-
# @since 1.1.0
|
5
|
-
# @api private
|
6
|
-
class Console < Command
|
7
|
-
# Supported engines
|
8
|
-
#
|
9
|
-
# @since 1.1.0
|
10
|
-
# @api private
|
11
|
-
ENGINES = {
|
12
|
-
'pry' => 'Pry',
|
13
|
-
'ripl' => 'Ripl',
|
14
|
-
'irb' => 'IRB'
|
15
|
-
}.freeze
|
16
|
-
|
17
|
-
requires "all"
|
18
|
-
desc "Starts Hanami console"
|
19
|
-
|
20
|
-
# TODO: OptParser support enums, extract to CLI
|
21
|
-
option :engine, desc: "Force a specific console engine: (#{ENGINES.keys.join('/')})"
|
22
|
-
|
23
|
-
example [
|
24
|
-
" # Uses the bundled engine",
|
25
|
-
"--engine=pry # Force to use Pry"
|
26
|
-
]
|
27
|
-
|
28
|
-
# Implements console code reloading
|
29
|
-
#
|
30
|
-
# @since 1.1.0
|
31
|
-
# @api private
|
32
|
-
module CodeReloading
|
33
|
-
# @since 1.1.0
|
34
|
-
# @api private
|
35
|
-
def reload!
|
36
|
-
puts 'Reloading...'
|
37
|
-
Kernel.exec "#{$PROGRAM_NAME} console"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# @since 1.1.0
|
42
|
-
# @api private
|
43
|
-
DEFAULT_ENGINE = ['irb'].freeze
|
44
|
-
|
45
|
-
# @since 1.1.0
|
46
|
-
# @api private
|
47
|
-
def call(options)
|
48
|
-
context = Context.new(options: options)
|
49
|
-
|
50
|
-
prepare
|
51
|
-
engine(context).start
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
# @since 1.1.0
|
57
|
-
# @api private
|
58
|
-
def engine(context)
|
59
|
-
load_engine context.options.fetch(:engine) { engine_lookup }
|
60
|
-
end
|
61
|
-
|
62
|
-
# @since 1.1.0
|
63
|
-
# @api private
|
64
|
-
def prepare
|
65
|
-
# Clear out ARGV so Pry/IRB don't attempt to parse the rest
|
66
|
-
ARGV.shift until ARGV.empty?
|
67
|
-
|
68
|
-
# Add convenience methods to the main:Object binding
|
69
|
-
TOPLEVEL_BINDING.eval('self').__send__(:include, CodeReloading)
|
70
|
-
end
|
71
|
-
|
72
|
-
# @since 1.1.0
|
73
|
-
# @api private
|
74
|
-
def engine_lookup
|
75
|
-
(ENGINES.find { |_, klass| Object.const_defined?(klass) } || DEFAULT_ENGINE).first
|
76
|
-
end
|
77
|
-
|
78
|
-
# @since 1.1.0
|
79
|
-
# @api private
|
80
|
-
def load_engine(engine)
|
81
|
-
require engine
|
82
|
-
Object.const_get(ENGINES.fetch(engine))
|
83
|
-
rescue LoadError, NameError
|
84
|
-
if ENGINES.key?(engine) # rubocop:disable Style/GuardClause
|
85
|
-
raise ArgumentError.new("Missing gem for `#{engine}' console engine. Please make sure to add it to `Gemfile'.")
|
86
|
-
else
|
87
|
-
raise ArgumentError.new("Unknown console engine: `#{engine}'.")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
register "console", Commands::Console, aliases: ["c"]
|
94
|
-
end
|
95
|
-
end
|