Module: Dapp::Deployment::Mod::Namespace

Included in:
App, Deployment
Defined in:
lib/dapp/deployment/mod/namespace.rb

Instance Method Summary collapse

Instance Method Details

#environmentObject



5
6
7
8
9
# File 'lib/dapp/deployment/mod/namespace.rb', line 5

def environment
  config._environment
    .merge(namespace_config_directive(:_environment) || {})
    .merge(system_environments)
end

#environmentsObject



18
19
20
21
22
23
# File 'lib/dapp/deployment/mod/namespace.rb', line 18

def environments
  [environment, secret_environment]
    .select { |env| !env.empty? }
    .map { |h| h.map { |k, v| { 'name' => k.to_s, 'value' => v.to_s } } }
    .flatten
end

#namespace_configObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dapp/deployment/mod/namespace.rb', line 34

def namespace_config
  @namespace_config = begin
    error_class = Error.const_get(self.class.name.to_s.split('::').last)
    if config._namespace.include?(namespace)
      config._namespace[namespace]
    elsif namespace.nil? || namespace == 'default'
      if config._namespace.one?
        config._namespace.values.first
      elsif config._namespace.empty?
      else
        if namespace.nil?
          raise error_class, code: :namespace_not_defined, data: { name: name }
        else
          raise error_class, code: :namespace_not_found, data: { namespace: namespace, name: name }
        end
      end
    else
      raise error_class, code: :namespace_not_found, data: { namespace: namespace, name: name }
    end
  end
end

#namespace_config_directive(name) ⇒ Object



29
30
31
32
# File 'lib/dapp/deployment/mod/namespace.rb', line 29

def namespace_config_directive(name)
  return if namespace_config.nil?
  namespace_config.send(name)
end

#scaleObject



25
26
27
# File 'lib/dapp/deployment/mod/namespace.rb', line 25

def scale
  namespace_config_directive(:_scale) || config._scale || 1
end

#secret_environmentObject



11
12
13
14
15
16
# File 'lib/dapp/deployment/mod/namespace.rb', line 11

def secret_environment
  return {} if secret.nil?
  config._secret_environment
    .merge(namespace_config_directive(:_secret_environment) || {})
    .each_with_object({}) { |(k, v), environments| environments[k] = secret.extract(v) }
end