Class: Ripe::CLI::Helper
- Inherits:
-
Object
- Object
- Ripe::CLI::Helper
- Defined in:
- lib/ripe/cli/helper.rb
Overview
This class defines helper methods for Ripe::CLI
.
Class Method Summary collapse
-
.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}.
-
.parse_config(filename) ⇒ Hash
Read and parse a json configuration file into a symbolized hash with the content of that file.
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}.
19 20 21 22 23 24 25 |
# File 'lib/ripe/cli/helper.rb', line 19 def self.parse_cli_opts() params = .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.
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 |