Class: Hanami::CLI::Commands::App::Command
- Inherits:
-
Hanami::CLI::Command
- Object
- Dry::CLI::Command
- Hanami::CLI::Command
- Hanami::CLI::Commands::App::Command
- Defined in:
- lib/hanami/cli/commands/app/command.rb
Overview
Base class for hanami CLI commands intended to be executed within an existing Hanami
app.
Direct Known Subclasses
Assets::Command, Console, DB::Command, Dev, Generate::Action, Generate::Command, Generate::Part, Generate::Repo, Generate::Slice, Generate::Struct, Generate::View, Install, Version
Defined Under Namespace
Modules: Environment
Class Method Summary collapse
- .inherited(klass) ⇒ Object private
Instance Method Summary collapse
-
#app ⇒ Hanami::App
Returns the Hanami app class.
- #inflector ⇒ Object
-
#measure(desc) ⇒ Object
Executes a given block and prints string to the
outstream with details of the time taken to execute. -
#run_command(klass) ⇒ Object
Runs another CLI command via its command class.
Methods inherited from Hanami::CLI::Command
Constructor Details
This class inherits a constructor from Hanami::CLI::Command
Class Method Details
.inherited(klass) ⇒ 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 58 |
# File 'lib/hanami/cli/commands/app/command.rb', line 55 def self.inherited(klass) super klass.prepend(Environment) end |
Instance Method Details
#app ⇒ Hanami::App
Returns the Hanami app class.
68 69 70 71 72 73 74 |
# File 'lib/hanami/cli/commands/app/command.rb', line 68 def app @app ||= begin require "hanami/prepare" Hanami.app end end |
#inflector ⇒ Object
76 |
# File 'lib/hanami/cli/commands/app/command.rb', line 76 def inflector = app.inflector |
#measure(desc) ⇒ Object
Executes a given block and prints string to the out stream with details of the time
taken to execute.
If the block returns a falsey value, then a failure message is printed.
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/hanami/cli/commands/app/command.rb', line 113 def measure(desc) start = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = yield stop = Process.clock_gettime(Process::CLOCK_MONOTONIC) if result out.puts "=> #{desc} in #{(stop - start).round(4)}s" else out.puts "!!! => #{desc.inspect} FAILED" end end |
#run_command(klass) ⇒ Object
Runs another CLI command via its command class.
85 86 87 88 89 90 |
# File 'lib/hanami/cli/commands/app/command.rb', line 85 def run_command(klass, ...) klass.new( out: out, fs: Hanami::CLI::Files, ).call(...) end |