Sha256: 8d92669d8f8aac01878ccbb59112beaaa3693105648ee162d2ce20e02f831cda

Contents?: true

Size: 991 Bytes

Versions: 2

Compression:

Stored size: 991 Bytes

Contents

require 'singleton'
require 'forwardable'

# This is the root configatron object, and contains methods which
# operate on the entire configatron hierarchy.
class Configatron::RootStore < BasicObject
  include ::Singleton
  extend ::Forwardable

  attr_reader :store

  # Have one global RootStore instance, but allow people to create
  # their own parallel ones if they desire.
  class << self
    public :new
  end

  def initialize
    @locked = false
    reset!
  end

  def method_missing(name, *args, &block)
    store.__send__(name, *args, &block)
  end

  def reset!
    @store = ::Configatron::Store.new(self)
  end

  def temp(&block)
    temp_start
    yield
    temp_end
  end

  def temp_start
    @temp = ::Configatron::DeepClone.deep_clone(@store)
  end

  def temp_end
    @store = @temp
  end

  def locked?
    @locked
  end

  def lock!
    @locked = true
  end

  def unlock!
    @locked = false
  end

  def_delegator :@store, :to_s
  def_delegator :@store, :inspect
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
configatron-4.2.1 lib/configatron/root_store.rb
configatron-4.2.0 lib/configatron/root_store.rb