module Moltrio::Config

Constants

ContainerCache
Undefined

Object to represent 'undefined' values, a-la javascript. Primarily useful for optional arguments for which 'nil' is a valid value.

VERSION

Public Instance Methods

configure(&block) click to toggle source
# File lib/moltrio/config.rb, line 13
def configure(&block)
  @configuration_block = block
  self
end
disable_caching() click to toggle source
# File lib/moltrio/config.rb, line 31
def disable_caching
  self.cached_containers = nil
end
enable_caching() click to toggle source
# File lib/moltrio/config.rb, line 27
def enable_caching
  self.cached_containers ||= ContainerCache.new
end
on_namespace(namespace) { || ... } click to toggle source
# File lib/moltrio/config.rb, line 35
def on_namespace(namespace)
  if block_given?
    prev_namespace = current_namespace
    switch_to_namespace!(namespace, strict: true)

    begin
      value = yield
    ensure
      switch_to_namespace!(prev_namespace, strict: false)
    end

    value
  else
    ChainContainer.new(chains_on_namespace(namespace))
  end
end
scoped(scope) click to toggle source
# File lib/moltrio/config/adapters/scoped.rb, line 8
def scoped(scope)
  Scoped.new(self, scope)
end
switch_to_namespace!(namespace, strict: true) click to toggle source
# File lib/moltrio/config.rb, line 52
def switch_to_namespace!(namespace, strict: true)
  if strict && !available_namespaces.include?(namespace)
    raise NoSuchNamespace.new(namespace)
  end

  self.current_namespace = namespace

  if cached_containers
    cached_containers.namespaced = nil
  end

  self
end

Private Instance Methods

chains_on_namespace(namespace) click to toggle source
# File lib/moltrio/config.rb, line 99
def chains_on_namespace(namespace)
  root_chains.map { |chain_name, chain|
    [chain_name, chain.on_namespace(namespace)]
  }
end
namespaced_container() click to toggle source
# File lib/moltrio/config.rb, line 79
def namespaced_container
  return cached_containers.namespaced if cached_containers && cached_containers.namespaced

  if current_namespace
    container = ChainContainer.new(chains_on_namespace(current_namespace))
  else
    container = root_container
  end

  if cached_containers
    cached_containers.namespaced = container
  end

  container
end
root_chains() click to toggle source
# File lib/moltrio/config.rb, line 95
def root_chains
  Builder.run(&@configuration_block).chains
end
root_container() click to toggle source
# File lib/moltrio/config.rb, line 68
def root_container
  return cached_containers.root if cached_containers && cached_containers.root
  container = ChainContainer.new(root_chains)

  if cached_containers
    cached_containers.root = container
  end

  container
end