Class: Envred

Inherits:
Object
  • Object
show all
Defined in:
lib/envred.rb,
lib/envred/version.rb

Constant Summary collapse

VERSION =
"0.4.1"

Instance Method Summary collapse

Constructor Details

#initialize(central, app) ⇒ Envred

Returns a new instance of Envred.



5
6
7
8
# File 'lib/envred.rb', line 5

def initialize(central, app)
  @central, @app = central, app
  @redis = Redis.new(url: "redis://#{@central}")
end

Instance Method Details

#applyObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/envred.rb', line 14

def apply
  load.each do |key, val|
    if val == ''
      ENV.delete(key)
    else
      ENV[key] = val if ENV[key] === nil
    end
  end

  yield if block_given?
end

#loadObject



10
11
12
# File 'lib/envred.rb', line 10

def load
  @redis.hgetall(@app) or []
end

#purgeObject



34
35
36
# File 'lib/envred.rb', line 34

def purge
  @redis.del(@app)
end

#set(*values) ⇒ Object



26
27
28
# File 'lib/envred.rb', line 26

def set(*values)
  @redis.hmset(@app, *values)
end

#unset(*keys) ⇒ Object



30
31
32
# File 'lib/envred.rb', line 30

def unset(*keys)
  @redis.hdel(@app, keys)
end