lib/gitmodel/persistable.rb in gitmodel-0.0.1 vs lib/gitmodel/persistable.rb in gitmodel-0.0.2
- old
+ new
@@ -95,11 +95,14 @@
dir = File.join(self.class.db_subdir, self.id)
transaction = options.delete(:transaction) || GitModel::Transaction.new(options)
result = transaction.execute do |t|
# Write the attributes to the attributes file
- t.index.add(File.join(dir, 'attributes.json'), JSON.pretty_generate(attributes))
+ # NOTE: using the redundant attributes.to_hash to work around a bug in
+ # active_support 3.0.4, remove when
+ # JSON.generate(HashWithIndifferentAccess.new) no longer fails.
+ t.index.add(File.join(dir, 'attributes.json'), JSON.pretty_generate(attributes.to_hash))
# Write the blob files
blobs.each do |name, data|
t.index.add(File.join(dir, name), data)
end
@@ -185,9 +188,10 @@
end
def find_all(conditions = {})
GitModel.logger.debug "Finding all #{name.pluralize} with conditions: #{conditions.inspect}"
results = []
+ return results unless GitModel.current_tree
dirs = (GitModel.current_tree / db_subdir).trees
dirs.each do |dir|
if dir.blobs.any?
o = new
o.send :load, File.join(db_subdir, dir.name)