dm-xml-adapter 0.575 → 0.576

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.
Files changed (2) hide show
  1. data/lib/dm-xml-adapter.rb +28 -28
  2. metadata +1 -1
@@ -147,9 +147,7 @@ module DataMapper::Adapters
147
147
  objects = []
148
148
  Dir[directory + "/*.xml"].each do |filename|
149
149
  # see if we have a nice cached version
150
- mtime = File.mtime(filename)
151
- cache_mtime = @cache.get_mtime(filename)
152
- if (mtime != nil and cache_mtime != nil and mtime == cache_mtime)
150
+ if has_cached_version?(filename)
153
151
  # we have a nice cached object..
154
152
  objects << @cache.get(model_name, file_to_id(filename))
155
153
  else
@@ -162,17 +160,16 @@ module DataMapper::Adapters
162
160
  end
163
161
  return objects
164
162
  end
163
+
164
+ def has_cached_version?(filename)
165
+ mtime = File.mtime(filename)
166
+ cache_mtime = @cache.get_mtime(filename)
167
+ return true if (mtime != nil and cache_mtime != nil and mtime == cache_mtime)
168
+ end
165
169
 
166
170
  def file_to_id(file)
167
171
  return file.match(/([0-9]+)\.xml/)[1]
168
172
  end
169
-
170
- def is_integer?(number)
171
- if number.class == String and number.match(/^\-*[0-9]+$/)
172
- return true
173
- end
174
- return false
175
- end
176
173
 
177
174
  def file_to_object(file, model)
178
175
  model_name = model.to_s
@@ -189,26 +186,30 @@ module DataMapper::Adapters
189
186
  child_class = child.attributes["class"]
190
187
  if child_class != nil
191
188
  # this means we have an attribute
192
- if (child_class == "String")
193
- new_obj.instance_variable_set("@#{child.name}", child.content)
194
- elsif (child_class == "Integer")
195
- new_obj.instance_variable_set("@#{child.name}", child.content.to_i)
196
- elsif (child_class == "TrueClass")
197
- new_obj.instance_variable_set("@#{child.name}", true)
198
- elsif (child_class == "FalseClass")
199
- new_obj.instance_variable_set("@#{child.name}", false)
200
- elsif (child_class == "BigDecimal")
201
- new_obj.instance_variable_set("@#{child.name}", BigDecimal.new(child.content))
202
- elsif (child_class == "DateTime")
203
- new_obj.instance_variable_set("@#{child.name}", DateTime.parse(child.content))
204
- end
189
+ populate_instance(new_obj, child, child_class)
205
190
  end
206
191
  end
207
192
 
208
193
  return new_obj
209
194
  end
195
+
196
+ def populate_instance(new_obj, child, child_class)
197
+ if (child_class == "String")
198
+ new_obj.instance_variable_set("@#{child.name}", child.content)
199
+ elsif (child_class == "Integer")
200
+ new_obj.instance_variable_set("@#{child.name}", child.content.to_i)
201
+ elsif (child_class == "TrueClass")
202
+ new_obj.instance_variable_set("@#{child.name}", true)
203
+ elsif (child_class == "FalseClass")
204
+ new_obj.instance_variable_set("@#{child.name}", false)
205
+ elsif (child_class == "BigDecimal")
206
+ new_obj.instance_variable_set("@#{child.name}", BigDecimal.new(child.content))
207
+ elsif (child_class == "DateTime")
208
+ new_obj.instance_variable_set("@#{child.name}", DateTime.parse(child.content))
209
+ end
210
+ end
210
211
 
211
- def find_free_id_for(class_name)
212
+ def find_free_id_for(class_name)
212
213
  # if there are no entries in the directory
213
214
  # or the directory doesn't exist
214
215
  # we need to create it...
@@ -231,7 +232,6 @@ module DataMapper::Adapters
231
232
  end
232
233
 
233
234
  def save(resource)
234
-
235
235
  # since we're saving, purge the cache
236
236
  resource_class = resource.class.to_s
237
237
  resource_key = resource.key.first
@@ -254,11 +254,11 @@ module DataMapper::Adapters
254
254
  value = resource.instance_variable_get("@" + property_name)
255
255
  # special case for false
256
256
  if property.primitive == TrueClass and value == false
257
- xml.tag!(property_name, false, :class => FalseClass.to_s)
257
+ xml.tag!(property_name, false, :class => FalseClass.to_s)
258
258
  elsif (property.primitive == BigDecimal and value != nil)
259
- xml.tag!(property_name, value.to_s("F"), :class => BigDecimal)
259
+ xml.tag!(property_name, value.to_s("F"), :class => BigDecimal)
260
260
  elsif (value != nil)
261
- xml.tag!(property_name, value, :class => property.primitive)
261
+ xml.tag!(property_name, value, :class => property.primitive)
262
262
  end
263
263
  end
264
264
  end
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.575"
4
+ version: "0.576"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Harding