-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcept.rb
More file actions
59 lines (50 loc) · 1 KB
/
Concept.rb
File metadata and controls
59 lines (50 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# This code is MIT licensed, so enjoy!
#
# Author: Joseph Austin
# Nodes and components are concepts, which simply maintains a universal
# data structure that can be freely accessed in a thread safe manner.
class Concept
@@fname = 'Data/core.data'
@@file = nil
@@mutex = Mutex.new
# On startup load the data
@@mutex.synchronize do
begin
File.open(@@fname, 'r') {|f| @@file = Marshal::load f}
rescue
@@file = {}
end
end
def initialize(data)
@data = data
end
def self.save
if @@file
@@mutex.synchronize do
File.open(@@fname, 'w') {|f| f.write Marshal::dump(@@file) }
end
end
end
# Test dump of data
def self.dump
puts @@file
end
protected
def _get(key)
r = nil
@@mutex.synchronize do
r = @data[key]
end
r
end
def _set(key, val)
@@mutex.synchronize do
@data[key] = val
end
end
def _remove(key)
@@mutex.synchronize do
@data.delete key unless @data[key].nil?
end
end
end