mongo_adaptor 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class MongoAdaptor
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/mongo_adaptor.rb CHANGED
@@ -26,7 +26,7 @@ class MongoAdaptor
26
26
  @collection.update query, set(process(model)), safe_mode.merge(upsert_mode false)
27
27
  end
28
28
 
29
- def fetch selector = {}, opts = {}
29
+ def fetch selector = {}, opts = { :fields => fields }
30
30
  @collection.find_one selector, opts.merge( :transformer => builder )
31
31
  end
32
32
 
@@ -34,7 +34,7 @@ class MongoAdaptor
34
34
  @collection.remove selector, opts
35
35
  end
36
36
 
37
- def find selector = {}, opts = {}
37
+ def find selector = {}, opts = { :fields => fields }
38
38
  @collection.find selector, opts.merge( :transformer => builder )
39
39
  end
40
40
 
@@ -45,12 +45,16 @@ class MongoAdaptor
45
45
  @klass.new.tap do |model|
46
46
  model[:id] = result.delete('_id') if model.respond_to?(:id)
47
47
  result.each do |field,value|
48
- model[field] = value if model.class.members.map(&:to_s).include?(field.to_s)
48
+ model[field] = value if fields.include?(field.to_s)
49
49
  end
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
+ def fields
55
+ @fields ||= @klass.members.map(&:to_s)
56
+ end
57
+
54
58
  def process(model)
55
59
  fields = {}
56
60
  model.each_pair { |field,value| fields[field] = value unless field == :id }
@@ -58,7 +62,7 @@ class MongoAdaptor
58
62
  end
59
63
 
60
64
  def safe_mode
61
- { :safe => true }
65
+ { :w => 1 }
62
66
  end
63
67
 
64
68
  def upsert_mode level
@@ -123,7 +123,7 @@ describe 'adapting structs into mongo' do
123
123
  subject.map(&:other).should == [0,1,2]
124
124
  end
125
125
  it 'will pass along options' do
126
- expect { adaptor.find({ :name => 'My Model' },{ fields: { }}) }.to_not raise_error
126
+ expect { adaptor.find({ :name => 'My Model' },{ :fields => { }}) }.to_not raise_error
127
127
  end
128
128
  end
129
129
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_adaptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: 1562466360637587669
125
+ hash: -706503449658322069
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: 1562466360637587669
134
+ hash: -706503449658322069
135
135
  requirements: []
136
136
  rubyforge_project:
137
137
  rubygems_version: 1.8.25