Class: Ripe::CLI::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/ripe/cli/helper.rb

Overview

This class defines helper methods for Ripe::CLI.

See Also:

Class Method Summary collapse

Class Method Details

.parse_cli_opts(options) ⇒ Hash

Parses a string representing a hash in the format of a=1,b=2,c=3 into a hash in the format of {a: 1, b: 2, c: 3}.

Parameters:

  • options (String)

    a hash in the format of a=1,b=2,c=3

Returns:

  • (Hash)

    a hash in the format of {a: 1, b: 2, c: 3}



19
20
21
22
23
24
25
# File 'lib/ripe/cli/helper.rb', line 19

def self.parse_cli_opts(options)
  params = options.split(/,/).map do |pair|
    key, value = pair.split(/=/)
    { key.to_sym => value }
  end
  params.inject(&:merge) || {}
end

.parse_config(filename) ⇒ Hash

Read and parse a json configuration file into a symbolized hash with the content of that file.

nothing if the file was not found or ill defined.

Parameters:

  • filename (String)

    name of a configuration file in json format

Returns:

  • (Hash)

    a symbolized hash of the content of the json file, or



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ripe/cli/helper.rb', line 35

def self.parse_config(filename)
  begin
    file = File.read(filename)
    begin
      JSON.parse(file, :symbolize_names => true)
    rescue
      abort "Configuration file found but ill defined: #{filename}"
    end
  rescue
    abort "Configuration file specified but not found: #{filename}"
  end
end