mongo_light 0.0.2 → 0.0.3

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.
@@ -45,10 +45,13 @@ module MongoLight
45
45
  end
46
46
  module InstanceMethods
47
47
  def initialize(attributes = {})
48
- attributes[:_id] = Id.new unless attributes.include?('_id') || attributes.include?(:_id)
49
- @attributes = attributes
48
+ @attributes = {:_id => (attributes['_id'] || attributes[:_id] || Id.new)}
50
49
  attributes.each do |k,v|
51
- send("#{k}=", v) unless k == :_id || k == '_id'
50
+ if self.class.map_include?(k)
51
+ @attributes[k] = v
52
+ elsif k != :_id && k != '_id'
53
+ send("#{k}=", v)
54
+ end
52
55
  end
53
56
  end
54
57
  def eql?(other)
@@ -70,11 +73,12 @@ module MongoLight
70
73
  def collection
71
74
  self.class.collection
72
75
  end
73
- def save(safe = false)
74
- collection.save(self.class.map(@attributes), {:safe => safe})
76
+ def save(options = nil)
77
+ opts = !options || options.include?(:safe) ? options : {:safe => options}
78
+ collection.save(self.class.map(@attributes), opts || {})
75
79
  end
76
- def save!
77
- save(true)
80
+ def save!(options = {})
81
+ save({:safe => true}.merge(options))
78
82
  end
79
83
  end
80
84
  end
@@ -64,12 +64,19 @@ module MongoLight
64
64
  return key unless @map.include?(key)
65
65
  @map[key].is_a?(Hash) ? @map[key][:field] : @map[key]
66
66
  end
67
+ def map_include?(key)
68
+ @map.include?(key)
69
+ end
67
70
  end
68
71
  module InstanceMethods
69
72
  def initialize(attributes = {})
70
- @attributes = attributes
73
+ @attributes = {}
71
74
  attributes.each do |k,v|
72
- send("#{k}=", v)
75
+ if self.class.map_include?(k)
76
+ @attributes[k] = v
77
+ else
78
+ send("#{k}=", v)
79
+ end
73
80
  end
74
81
  end
75
82
  def [](name)
@@ -1,3 +1,3 @@
1
1
  module MongoLight
2
- Version = '0.0.2'
2
+ Version = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_light
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-13 00:00:00.000000000 Z
12
+ date: 2011-10-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project:
50
- rubygems_version: 1.8.6
50
+ rubygems_version: 1.8.10
51
51
  signing_key:
52
52
  specification_version: 3
53
53
  summary: A Lightweight ORM for Rails and MongoDB