Module: Moltrio::Config

Extended by:
Config, ThreadAttrAccessor
Included in:
Config
Defined in:
lib/moltrio/config.rb,
lib/moltrio/errors.rb,
lib/moltrio/config/builder.rb,
lib/moltrio/config/version.rb,
lib/moltrio/config/undefined.rb,
lib/moltrio/config/adapter_chain.rb,
lib/moltrio/config/chain_builder.rb,
lib/moltrio/config/adapters/scoped.rb,
lib/moltrio/config/chain_container.rb,
lib/moltrio/config/storage/storage.rb,
lib/moltrio/config/adapters/adapter.rb,
lib/moltrio/config/storage/file_storage.rb,
lib/moltrio/config/adapters/single_file_adapter.rb,
lib/moltrio/config/adapters/database_yml_adapter.rb,
lib/moltrio/config/adapters/single_redis_adapter.rb,
lib/moltrio/config/adapters/env_variables_adapter.rb,
lib/moltrio/config/adapters/multitenant_redis_adapter.rb,
lib/moltrio/config/adapters/multitenant_directory_adapter.rb

Defined Under Namespace

Classes: Adapter, AdapterChain, Builder, ChainBuilder, ChainContainer, ContainerCache, DatabaseYmlAdapter, EnvVariablesAdapter, FileStorage, MultitenantDirectoryAdapter, MultitenantRedisAdapter, NoSuchNamespace, Scoped, SingleFileAdapter, SingleRedisAdapter, Storage

Constant Summary collapse

VERSION =
"0.1.1"
Undefined =

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

Object.new.freeze

Instance Method Summary collapse

Instance Method Details

#configure(&block) ⇒ Object



13
14
15
16
# File 'lib/moltrio/config.rb', line 13

def configure(&block)
  @configuration_block = block
  self
end

#disable_cachingObject



31
32
33
# File 'lib/moltrio/config.rb', line 31

def disable_caching
  self.cached_containers = nil
end

#enable_cachingObject



27
28
29
# File 'lib/moltrio/config.rb', line 27

def enable_caching
  self.cached_containers ||= ContainerCache.new
end

#on_namespace(namespace) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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

#switch_to_namespace!(namespace, strict: true) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# 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