mm-files 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module MmFiles
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
7
7
 
8
8
  require 'mongomapper'
@@ -23,7 +23,7 @@ module MongoMapper
23
23
 
24
24
  def self.fetch(owner, filename)
25
25
  db = owner.class.database
26
- criteria, options = FinderOptions.new(:filename => filename, :metadata => owner.id, :limit => 1).to_a
26
+ criteria, options = FinderOptions.new(:filename => filename, :metadata => {:_id => owner.id}, :limit => 1).to_a
27
27
 
28
28
  obj = db.collection("#{owner.collection.name}.files").find(criteria, options).next_object
29
29
  if obj
@@ -1,16 +1,16 @@
1
1
  module MongoMapper
2
2
  module Files
3
- def self.included?(model)
3
+ def self.included(model)
4
4
  model.class_eval do
5
5
  after_create :_sync_pending_files
6
6
  end
7
7
  end
8
8
 
9
- def put_file(filename, data)
9
+ def put_file(filename, data, metadata = {})
10
10
  if !new?
11
11
  XGen::Mongo::GridFS::GridStore.open(self.class.database, filename, "w",
12
12
  :root => self.collection.name,
13
- :metadata => self.id) do |f|
13
+ :metadata => metadata.deep_merge({:_id => self.id})) do |f|
14
14
  f << data
15
15
  end
16
16
  else
@@ -23,7 +23,7 @@ module MongoMapper
23
23
  end
24
24
 
25
25
  def files
26
- criteria, options = FinderOptions.new(:metadata => self.id).to_a
26
+ criteria, options = FinderOptions.new(:metadata => {:_id => self.id}).to_a
27
27
  coll = self.class.database.collection("#{self.collection.name}.files")
28
28
  @files = coll.find(criteria, options).map do |a|
29
29
  MongoMapper::File.new(self, a)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cuadrado
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-04 00:00:00 -05:00
12
+ date: 2009-08-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency