Module: ParamsHelper

Includes:
TddiumConstant
Included in:
Tddium::TddiumCli
Defined in:
lib/tddium/cli/params_helper.rb

Overview

Copyright © 2014 Solano Labs All Rights Reserved

Instance Method Summary collapse

Instance Method Details

#displayObject



29
30
31
32
33
34
35
# File 'lib/tddium/cli/params_helper.rb', line 29

def display
  store_params = load_params(false)
  say 'Options:'
  store_params.each do |k, v|
    say "   #{k.capitalize}:\t#{v}"
  end
end

#load_params(defaults = true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/tddium/cli/params_helper.rb', line 6

def load_params(defaults=true)
  params = {}
  if File.exists?(Default::PARAMS_PATH) then
    File.open(Default::PARAMS_PATH, 'r') do |file|
      params = JSON.parse file.read
    end
  elsif !defaults then
    abort Text::Process::NOT_SAVED_OPTIONS
  end
  return params
end

#write_params(options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/tddium/cli/params_helper.rb', line 18

def write_params options
  begin
    File.open(Default::PARAMS_PATH, File::CREAT|File::TRUNC|File::RDWR, 0600) do |file|
      file.write options.to_json
    end
    say Text::Process::OPTIONS_SAVED
  rescue Exception => e
    say Text::Error::OPTIONS_NOT_SAVED
  end
end