Class: Idonethis::UseCases::App

Inherits:
Object
  • Object
show all
Defined in:
lib/idonethis/use_cases/app.rb

Class Method Summary collapse

Class Method Details

.apply(argv = {}, adapters = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/idonethis/use_cases/app.rb', line 6

def apply(argv={}, adapters={})
  args = Options.parse(argv)

  command,*rest = argv

  command = "help" unless command

  log      = args[:verbose] == true ? adapters[:log] : ->(_){} 
  internet = adapters[:internet] 
  views    = adapters[:views]    || fail("You need to supply the :views adapter")
  settings = adapters[:settings] || fail("You need to supply the :settings adapters")
  
  args.merge!({ opts: rest, log: log, internet: internet, view: views[:list]})

  log.call "args: #{args}, command: #{command}, rest: #{rest}"
  
  use_case = choose command.to_sym, adapters, views, rest 

  unless use_case
    log.call "No command <#{command.to_sym}> found"
    return
  end

  use_case.call settings.credential, args
end