Class: BlendSpreadsheetLoanGenerator::Init

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/blend_spreadsheet_loan_generator/init.rb

Instance Method Summary collapse

Instance Method Details

#call(client_id:, client_secret:) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/blend_spreadsheet_loan_generator/init.rb', line 7

def call(client_id:, client_secret:)
  if !ENV.key?('SPREADSHEET_LOAN_GENERATOR_DIR')
    puts "Please set up the environment variable SPREADSHEET_LOAN_GENERATOR_DIR to a dir that will store this gem's configuration"
    return
  end

  create_config_dir
  create_config_file(client_id: client_id, client_secret: client_secret)
end

#config_pathObject



17
18
19
# File 'lib/blend_spreadsheet_loan_generator/init.rb', line 17

def config_path
  File.join(ENV['SPREADSHEET_LOAN_GENERATOR_DIR'], 'config.json')
end

#create_config_dirObject



21
22
23
24
25
# File 'lib/blend_spreadsheet_loan_generator/init.rb', line 21

def create_config_dir
  if !File.exists?(ENV['SPREADSHEET_LOAN_GENERATOR_DIR'])
    FileUtils.mkdir_p(ENV['SPREADSHEET_LOAN_GENERATOR_DIR'])
  end
end

#create_config_file(client_id:, client_secret:) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/blend_spreadsheet_loan_generator/init.rb', line 27

def create_config_file(client_id:, client_secret:)
  f = File.new(config_path, 'w')
  f.write({
    client_id: client_id,
    client_secret: client_secret
  }.to_json)
  f.close
end