Class: DotenvUtil
- Inherits:
-
Object
- Object
- DotenvUtil
- Defined in:
- lib/dotenv_util.rb
Overview
Provides Generic support for manipulating Dotenv files
Constant Summary collapse
- LINE =
Retrieved from github.com/bkeepers/dotenv/blob/master/lib/dotenv/parser.rb
/ \A \s* (?:export\s+)? # optional export ([\w\.]+) # key (?:\s*=\s*|:\s+?) # separator ( # optional value begin '(?:\'|[^'])*' # single quoted value | # or "(?:\"|[^"])*" # double quoted value | # or [^#\n]+ # unquoted value )? # value end \s* (?:\#.*)? # optional comment \z /x
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#env_text ⇒ Object
readonly
Returns the value of attribute env_text.
Instance Method Summary collapse
- #generate_env ⇒ Object
-
#initialize(env_file) ⇒ DotenvUtil
constructor
A new instance of DotenvUtil.
- #set(target, value) ⇒ Object
Constructor Details
#initialize(env_file) ⇒ DotenvUtil
Returns a new instance of DotenvUtil.
26 27 28 29 |
# File 'lib/dotenv_util.rb', line 26 def initialize(env_file) @env_text = env_file @env = parse_env_file end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
25 26 27 |
# File 'lib/dotenv_util.rb', line 25 def env @env end |
#env_text ⇒ Object (readonly)
Returns the value of attribute env_text.
25 26 27 |
# File 'lib/dotenv_util.rb', line 25 def env_text @env_text end |
Instance Method Details
#generate_env ⇒ Object
35 36 37 38 39 40 |
# File 'lib/dotenv_util.rb', line 35 def generate_env env.collect do |key, val| val = %("#{val}") if val =~ /\s/ "#{key}=#{val}" end.join("\n") end |
#set(target, value) ⇒ Object
31 32 33 |
# File 'lib/dotenv_util.rb', line 31 def set(target, value) env[target] = value end |