mordor 0.2.2 → 0.2.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.
@@ -14,7 +14,7 @@ module Mordor
14
14
 
15
15
  def replace_params(params = {})
16
16
  result = {}
17
- return result unless params
17
+ return result if params.nil? or params.empty?
18
18
  params.each do |key, value|
19
19
  value = replace_type(value)
20
20
  key = key.to_s.gsub(/\W|\./, "_")
@@ -37,6 +37,8 @@ module Mordor
37
37
  value = value.map do |val|
38
38
  replace_type(val)
39
39
  end
40
+ when BSON::Timestamp
41
+ value = replace_params({:seconds => value ? value.seconds : 0, :increment => value ? value.increment : 0})
40
42
  when Integer
41
43
  else
42
44
  value = value.to_s
@@ -65,8 +67,11 @@ module Mordor
65
67
  self_hash = self.to_hash
66
68
  if timestamp_attribute = self.class.timestamped_attribute
67
69
  timestamp_value = self_hash.delete(timestamp_attribute)
70
+ if timestamp_value.is_a?(Hash)
71
+ timestamp_value = BSON::Timestamp.new(timestamp_value["seconds"], timestamp_value["increment"])
72
+ end
68
73
  ordered_self_hash = BSON::OrderedHash.new
69
- ordered_self_hash[timestamp_attribute] = (timestamp_value.nil? || timestamp_value.empty?) ? BSON::Timestamp.new(0, 0) : timestamp_value
74
+ ordered_self_hash[timestamp_attribute] = (timestamp_value.nil?) ? BSON::Timestamp.new(0, 0) : timestamp_value
70
75
  self_hash.each do |key, value|
71
76
  ordered_self_hash[key] = value
72
77
  end
@@ -74,7 +79,6 @@ module Mordor
74
79
  end
75
80
  insert_id = self.class.collection.insert(self_hash)
76
81
  self._id = insert_id
77
- self.reload
78
82
  else
79
83
  insert_id = self.update
80
84
  end
data/mordor.gemspec CHANGED
@@ -2,8 +2,8 @@ Gem::Specification.new do |s|
2
2
  s.name = "mordor"
3
3
 
4
4
  # Do not set the version and date field manually, this is done by the release script
5
- s.version = "0.2.2"
6
- s.date = "2011-12-28"
5
+ s.version = "0.2.3"
6
+ s.date = "2012-01-02"
7
7
 
8
8
  s.summary = "mordor"
9
9
  s.description = <<-eos
@@ -96,6 +96,7 @@ describe "with respect to resources" do
96
96
 
97
97
  it "should provide timestamped attribute as first attribute when creating a Resource" do
98
98
  tr = TestResource.create({:first => 'first'})
99
+ tr.reload
99
100
  tr.at.should_not be_nil
100
101
  TestResource.get(tr._id).at.should_not == BSON::Timestamp.new(0,0)
101
102
  end
@@ -134,6 +135,17 @@ describe "with respect to resources" do
134
135
  end
135
136
  end
136
137
 
138
+ it "should correctly replace BSON::Timestampls" do
139
+ options = {
140
+ "option" => BSON::Timestamp.new(324244, 12)
141
+ }
142
+ result = TestResource.new.replace_params(options)
143
+ result.each do |k, v|
144
+ v["seconds"].should == 324244
145
+ v["increment"].should == 12
146
+ end
147
+ end
148
+
137
149
  it "should correctly respond to to_hash" do
138
150
  resource = TestResource.new({:first => "first", :second => "second", :third => "third"})
139
151
  hash = resource.to_hash
@@ -142,6 +154,7 @@ describe "with respect to resources" do
142
154
  hash[:second].should == "second"
143
155
  hash[:third].should == "third"
144
156
  end
157
+
145
158
  end
146
159
 
147
160
  context "with respect to creating" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mordor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan-Willem Koelewijn
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-28 00:00:00 +01:00
19
+ date: 2012-01-02 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency