Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configuration file for a standalone ruby script

I have a ruby script that runs on a linux server. Its not using rails or anything. Its basically a commandline ruby script that can be passed arguments like this: ./ruby_script.rb arg1 arg2

How can I abstract away the arguments into a configuration file such as a yaml file or something? Can you provide an example of how this can be done?

Thank you in advance.

like image 249
Doublespeed Avatar asked Jul 15 '13 16:07

Doublespeed


1 Answers

First, you can run an independent script that writes to a YAML configuration file:

require "yaml"
File.write("path_to_yaml_file", [arg1, arg2].to_yaml)

Then, read it within your app:

require "yaml"
arg1, arg2 = YAML.load_file("path_to_yaml")
# use arg1, arg2
...
like image 195
sawa Avatar answered Sep 29 '22 06:09

sawa