Module: Idonethis::UseCases::Config

Defined in:
lib/idonethis/use_cases/config.rb

Class Method Summary collapse

Class Method Details

.apply(_, args = {}) ⇒ Object



4
5
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/config.rb', line 4

def apply(_, args={})
  log       = args[:log]  || fail("You need to supply :log adapter")
  
  log.call "args: #{args}"

  require 'yaml'

  settings = File.exists?(filename) ? YAML.load_file(filename) : {}

  token = (args[:opts].map{|it| it.match /user.token=(.+)/}.compact || []).first

  if token
    File.open filename, "w+" do |f|
      f.puts(settings.merge({token: token[1]}).to_yaml)
    end
  end

  team = (args[:opts].map{|it| it.match /user.team=(.+)/}.compact || []).first

  if team
    File.open filename, "w+" do |f|
      f.puts(settings.merge({team: team[1]}).to_yaml)
    end
  end

  puts "Settings saved to <#{filename}>"
end