class Capistrano::Dotenv::Config
Constants
- VARIABLE_PATTERN
Attributes
contents[R]
variables[R]
Public Class Methods
new(contents = ''.freeze)
click to toggle source
# File lib/capistrano/dotenv/config.rb, line 10 def initialize(contents = ''.freeze) @contents = contents.to_s @variables = {} add(*@contents.lines) end
Public Instance Methods
add(*args)
click to toggle source
# File lib/capistrano/dotenv/config.rb, line 27 def add(*args) args.each do |string| if (variable = extract_variable_from(string.strip)) key, value = variable set(key, value) end end end
compile()
click to toggle source
# File lib/capistrano/dotenv/config.rb, line 20 def compile Hash[variables.sort].map do |key, value| %(#{ key }=#{ value }) end.join("\n") << "\n" end
Also aliased as: to_s
remove(*args)
click to toggle source
# File lib/capistrano/dotenv/config.rb, line 36 def remove(*args) args.each do |key| variables.delete(key) end end
set(key, value)
click to toggle source
# File lib/capistrano/dotenv/config.rb, line 16 def set(key, value) variables[key] = value end
to_io()
click to toggle source
# File lib/capistrano/dotenv/config.rb, line 42 def to_io StringIO.new(compile) end
Private Instance Methods
extract_variable_from(string)
click to toggle source
# File lib/capistrano/dotenv/config.rb, line 48 def extract_variable_from(string) if (matches = string.match(VARIABLE_PATTERN)) key = matches[1] value = matches[2] if key && value [key, value] end end end