Class: Configatron::RootStore

Inherits:
BasicObject
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/configatron/root_store.rb

Overview

This is the root configatron object, and contains methods which operate on the entire configatron hierarchy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRootStore

Returns a new instance of RootStore.



18
19
20
21
# File 'lib/configatron/root_store.rb', line 18

def initialize
  @locked = false
  reset!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



23
24
25
# File 'lib/configatron/root_store.rb', line 23

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

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



10
11
12
# File 'lib/configatron/root_store.rb', line 10

def store
  @store
end

Instance Method Details

#lock!(&blk) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/configatron/root_store.rb', line 55

def lock!(&blk)
  if blk
    orig = @locked
    begin
      @locked = true
      blk.call
    ensure
      @locked = orig
    end
  else
    @locked = true
  end
end

#locked?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/configatron/root_store.rb', line 51

def locked?
  @locked
end

#reset!Object



27
28
29
# File 'lib/configatron/root_store.rb', line 27

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

#temp(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/configatron/root_store.rb', line 31

def temp(&block)
  temp_start

  begin
    yield
  ensure
    temp_end
  end
end

#temp_endObject



46
47
48
49
# File 'lib/configatron/root_store.rb', line 46

def temp_end
  @store = @temp
  @locked = @temp_locked
end

#temp_startObject



41
42
43
44
# File 'lib/configatron/root_store.rb', line 41

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

#unlock!(&blk) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/configatron/root_store.rb', line 69

def unlock!(&blk)
  if blk
    orig = @locked
    begin
      @locked = false
      blk.call
    ensure
      @locked = orig
    end
  else
    @locked = false
  end
end