Module: Gel::DB::AutoTransaction

Included in:
File, PStore, SDBM
Defined in:
lib/gel/db.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/gel/db.rb', line 120

def [](key)
  if read?
    super
  else
    reading { super }
  end
end

#[]=(key, value) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/gel/db.rb', line 128

def []=(key, value)
  if write?
    super
  else
    writing { super }
  end
end

#each_keyObject



104
105
106
107
108
109
110
# File 'lib/gel/db.rb', line 104

def each_key
  if read?
    super
  else
    reading { super }
  end
end

#initialize(root, name) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/gel/db.rb', line 46

def initialize(root, name)
  @root = root
  @name = name

  super

  @transaction = nil
  @monitor = Monitor.new
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
115
116
117
118
# File 'lib/gel/db.rb', line 112

def key?(key)
  if read?
    super
  else
    reading { super }
  end
end

#nested?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/gel/db.rb', line 74

def nested?
  owned? && @transaction
end

#owned?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/gel/db.rb', line 57

def owned?
  @monitor.mon_owned?
end

#read?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/gel/db.rb', line 70

def read?
  owned? && @transaction
end

#readingObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/gel/db.rb', line 91

def reading
  raise if nested?

  @monitor.synchronize do
    begin
      @transaction = :read
      super
    ensure
      @transaction = nil
    end
  end
end

#write?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/gel/db.rb', line 66

def write?
  owned? && @transaction == :write
end

#writingObject



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gel/db.rb', line 78

def writing
  raise if nested?

  @monitor.synchronize do
    begin
      @transaction = :write
      super
    ensure
      @transaction = nil
    end
  end
end