Sha256: a30286b3817bf46432281d5b40fa8c93e9c4f64c1466cb7198ef36064ade57b4

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require "dry/files"

require_relative "db/utils/database"

module Hanami
  module CLI
    module Commands
      class Application < Hanami::CLI::Command
        module Environment
          def call(**opts)
            env = opts[:env]
            ENV["HANAMI_ENV"] = env.to_s
            super(**opts)
          end
        end

        def self.inherited(klass)
          super
          klass.option(:env, required: false, default: "development", desc: "Application's environment")
          klass.prepend(Environment)
        end

        def application
          @application ||=
            begin
              require "hanami/init"
              Hanami.application
            end
        end

        def run_command(klass, *args)
          klass.new(
            out: out,
            inflector: application.inflector,
            fs: Dry::Files
          ).call(*args)
        end

        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

        def database
          @database ||= Commands::DB::Utils::Database[application]
        end

        def database_config
          database.config
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-cli-2.0.0.alpha4 lib/hanami/cli/commands/application.rb
hanami-cli-2.0.0.alpha3 lib/hanami/cli/commands/application.rb
hanami-cli-2.0.0.alpha2 lib/hanami/cli/commands/application.rb