Class: Envfile
- Inherits:
-
Hash
- Object
- Hash
- Envfile
- Defined in:
- lib/envfile.rb
Overview
Envfile understands various input file formats and executes commands according to that.
It should be noted that Envfile is (unlike the ENV object itself) a kind of Hash. So if you want to modify some environment variables, feel free to do so as you normally do with Hashes. It is of course up to you to properly set them up.
Class Method Summary collapse
-
.run_with_envfile(envfile, cmd, *argv) ⇒ Object
Utility method to setup, fire, then forget.
Instance Method Summary collapse
-
#exec!(cmd, argv) ⇒ Object
Executes the given cmd under self’s setup.
-
#parse(envfile) ⇒ Object
Load up the contents of the given file.
Class Method Details
.run_with_envfile(envfile, cmd, *argv) ⇒ Object
Utility method to setup, fire, then forget.
43 44 45 |
# File 'lib/envfile.rb', line 43 def self.run_with_envfile envfile, cmd, *argv new.parse(envfile).exec!(cmd, argv) end |
Instance Method Details
#exec!(cmd, argv) ⇒ Object
This method does not always return. But when it does it always results into an exception.
Executes the given cmd under self’s setup.
75 76 77 |
# File 'lib/envfile.rb', line 75 def exec! cmd, argv exec self, [cmd, cmd], *argv, close_others: true end |
#parse(envfile) ⇒ Object
When called multiple times with different envfile per instance, and if any of the env key collides, the result is undefined. I would like to advise you no to do such thing.
Load up the contents of the given file.
53 54 55 56 57 58 59 60 61 |
# File 'lib/envfile.rb', line 53 def parse envfile path = Pathname.new envfile update case path.extname when '.pl', '.perl' then parse_perl path when '.js', '.json' then parse_json path when '.yml', '.yaml' then parse_yaml path else parse_xaicron path end end |