Class: Etcenv::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/etcenv/environment.rb

Defined Under Namespace

Classes: DepthLimitError, EtcvaultFailure, KeyNotFound, LoopError, NotDirectory

Constant Summary collapse

INCLUDE_KEY =
'.include'
MAX_DEPTH_DEFAULT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(etcd, root_key, max_depth: MAX_DEPTH_DEFAULT) ⇒ Environment

Returns a new instance of Environment.



16
17
18
19
20
21
22
# File 'lib/etcenv/environment.rb', line 16

def initialize(etcd, root_key, max_depth: MAX_DEPTH_DEFAULT)
  @etcd = etcd
  @root_key = root_key
  @max_depth = max_depth
  @lock = Mutex.new
  load
end

Instance Attribute Details

#cluster_indexObject (readonly)

Returns the value of attribute cluster_index.



24
25
26
# File 'lib/etcenv/environment.rb', line 24

def cluster_index
  @cluster_index
end

#envObject (readonly)

Returns the value of attribute env.



24
25
26
# File 'lib/etcenv/environment.rb', line 24

def env
  @env
end

#etcdObject (readonly)

Returns the value of attribute etcd.



24
25
26
# File 'lib/etcenv/environment.rb', line 24

def etcd
  @etcd
end

#max_depthObject

Returns the value of attribute max_depth.



25
26
27
# File 'lib/etcenv/environment.rb', line 25

def max_depth
  @max_depth
end

#root_keyObject (readonly)

Returns the value of attribute root_key.



24
25
26
# File 'lib/etcenv/environment.rb', line 24

def root_key
  @root_key
end

Instance Method Details

#expanded_envObject



27
28
29
# File 'lib/etcenv/environment.rb', line 27

def expanded_env
  VariableExpander.expand(env)
end

#keysObject



35
36
37
# File 'lib/etcenv/environment.rb', line 35

def keys
  modified_indices.keys
end

#loadObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/etcenv/environment.rb', line 39

def load
  @lock.synchronize do
    flush
    env = {}
    includes.each do |name|
      env.merge! fetch(name)
    end
    env.delete '.include'
    @env = env
  end
  self
end

#modified_indicesObject



31
32
33
# File 'lib/etcenv/environment.rb', line 31

def modified_indices
  @modified_indices ||= {}
end