dm-xml-adapter 0.53 → 0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dm-xml-adapter.rb +31 -30
- metadata +2 -2
data/lib/dm-xml-adapter.rb
CHANGED
@@ -23,12 +23,12 @@ module DataMapper::Adapters
|
|
23
23
|
|
24
24
|
def set_mtime(file, mtime)
|
25
25
|
#@@logger.info("Saved mtime, #{file} -> #{mtime}")
|
26
|
-
|
26
|
+
@mtimes[file] = mtime
|
27
27
|
end
|
28
28
|
|
29
29
|
def delete_mtime(file)
|
30
30
|
#@@logger.info("deleting the following mtime: #{file}")
|
31
|
-
|
31
|
+
@mtimes.delete(file)
|
32
32
|
end
|
33
33
|
|
34
34
|
def get_mtime(file)
|
@@ -36,37 +36,36 @@ module DataMapper::Adapters
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def put(classname, id, object)
|
39
|
-
|
40
|
-
# @@logger.info("CACHE INSERT: #{classname} #{id} #{object.inspect}")
|
39
|
+
#@@logger.info("CACHE INSERT: #{classname} #{id} #{object.inspect}")
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
# check to see if we have a classname entry
|
42
|
+
if (@classes[classname] == nil)
|
43
|
+
@classes[classname] = Hash.new
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
hash = @classes[classname]
|
47
|
+
hash[id.to_s] = object
|
48
|
+
# @@logger.info("the hash is: #{hash.inspect}")
|
50
49
|
end
|
51
50
|
|
52
51
|
def delete(classname, id)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
#@@logger.info("deleted the following from cache: #{classname} #{id.to_s}")
|
53
|
+
hash = @classes[classname]
|
54
|
+
#@@logger.info("the hash is: #{hash.inspect}")
|
55
|
+
unless hash == nil
|
56
|
+
hash.delete(id.to_s)
|
57
|
+
end
|
58
|
+
#@@logger.info("the hash is: #{hash.inspect}")
|
60
59
|
end
|
61
60
|
|
62
61
|
def get(classname, id)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
#@@logger.info("CACHE FETCH: #{classname} #{id}")
|
63
|
+
#@@logger.info("Master classes: #{@classes.inspect}")
|
64
|
+
hash = @classes[classname]
|
65
|
+
#@@logger.info("the hash is: #{hash.inspect}")
|
66
|
+
object = hash[id]
|
67
|
+
#@@logger.info("The object is: #{object}")
|
68
|
+
return object
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
@@ -83,7 +82,7 @@ module DataMapper::Adapters
|
|
83
82
|
|
84
83
|
@cache = XmlAdapterCache.new
|
85
84
|
|
86
|
-
|
85
|
+
#@@logger = Log4r::Logger.new 'adapter'
|
87
86
|
#@@logger.outputters = Log4r::Outputter.stdout
|
88
87
|
|
89
88
|
end
|
@@ -162,17 +161,19 @@ module DataMapper::Adapters
|
|
162
161
|
end
|
163
162
|
|
164
163
|
def get_all(model)
|
164
|
+
#@@logger.info("Trying to get all: #{model.to_s}")
|
165
165
|
objects = Array.new
|
166
166
|
directory = classname_to_dir(model.to_s)
|
167
167
|
if ! File.exists?(directory)
|
168
|
+
#@@logger.error("The directory doesn't exist!")
|
168
169
|
return objects
|
169
170
|
end
|
170
|
-
Dir.
|
171
|
-
|
171
|
+
Dir.entries(directory).select {|f| f.match(/\.xml$/) }.each do |filename|
|
172
|
+
filename = directory + "/" + filename
|
172
173
|
file = File.new(filename)
|
173
174
|
# see if we have a nice cached version
|
174
175
|
if (@cache.get_mtime(filename) == nil or file.mtime > @cache.get_mtime(filename))
|
175
|
-
|
176
|
+
#@@logger.info("CACHE MISS")
|
176
177
|
# the file's newer, so we gotta load it up
|
177
178
|
object = file_to_object(filename, model)
|
178
179
|
objects << object
|
@@ -180,7 +181,7 @@ module DataMapper::Adapters
|
|
180
181
|
@cache.set_mtime(filename, file.mtime)
|
181
182
|
else
|
182
183
|
# @@logger.info("YES !!!")
|
183
|
-
|
184
|
+
#@@logger.info("CACHE HIT")
|
184
185
|
# @@logger.info("the file is: #{file}")
|
185
186
|
# the file was older than what we had so cache is fine
|
186
187
|
objects << @cache.get(model.to_s, file_to_id(filename))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-xml-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.54"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Harding
|
@@ -9,7 +9,7 @@ autorequire: dm-xml-adapter
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-29 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|