Module: Eco::API::Common::Loaders::UseCase::CliIdentify

Included in:
Eco::API::Common::Loaders::UseCase
Defined in:
lib/eco/api/common/loaders/use_case/cli_identify.rb

Instance Method Summary collapse

Instance Method Details

#cli(cli_class = nil) ⇒ Object

TODO:

check if @cli should really be fixed to a value (currently not).

It uses the cli_class to install the Cli. If not given, it tries to identify if there's a Case::Cli constant defined that it is a Cli class.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/eco/api/common/loaders/use_case/cli_identify.rb', line 10

def cli(cli_class = nil)
  if cli_class.is_a?(Class)
    msg = 'cli_class should inherit from Eco::API::UseCases::Cli'
    raise ArgumentError, msg unless cli_class < Eco::API::UseCases::Cli

    @cli = cli_class
  elsif cli_class.nil?
    return @cli if instance_variable_defined?(:@cli) && !@cli.nil?

    # try to see if it's namespaced after the use case it provisions cli integration

    begin
      try_class = [to_s, 'Cli'].join('::')
      @cli = Kernel.const_get(try_class)
    rescue NameError
      nil
    end
  else
    raise ArgumentError, "Expecting a class. Given: #{cli_class.class} object"
  end
end

#cli!Object



3
4
5
# File 'lib/eco/api/common/loaders/use_case/cli_identify.rb', line 3

def cli!
  cli&.apply!
end