Skip to content

Commit

Permalink
rename openstruct type and fix test
Browse files Browse the repository at this point in the history
Signed-off-by: David A. Cuadrado <krawek@gmail.com>
  • Loading branch information
dcu committed Mar 4, 2012
1 parent f5c5659 commit 14267b0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/mongoid_ext/paranoia.rb
Expand Up @@ -86,7 +86,7 @@ def restore
end

def self.compact!(date = 1.month.ago)
self.delete_all(:created_at.lte => date)
self.delete_all(:created_at => {:$lte => date.to_time})
end

private
Expand Down
22 changes: 12 additions & 10 deletions lib/mongoid_ext/types/open_struct.rb
@@ -1,17 +1,19 @@
require 'ostruct'

class OpenStruct
include Mongoid::Fields::Serializable
module MongoidExt
class OpenStruct < ::OpenStruct
include Mongoid::Fields::Serializable

def serialize(value)
value.nil? ? nil : value.to_hash
end
def serialize(value)
value.nil? ? nil : value.to_hash
end

def deserialize(value)
value.nil? ? nil : OpenStruct.new(value || {})
end
def deserialize(value)
value.nil? ? nil : OpenStruct.new(value || {})
end

def to_hash
send(:table)
def to_hash
send(:table)
end
end
end
2 changes: 1 addition & 1 deletion test/models.rb
Expand Up @@ -41,7 +41,7 @@ class Avatar # for Storage and File

class UserConfig #for OpenStruct
include Mongoid::Document
field :entries, :type => OpenStruct
field :entries, :type => MongoidExt::OpenStruct
end

class User
Expand Down
2 changes: 1 addition & 1 deletion test/types/test_open_struct.rb
Expand Up @@ -11,7 +11,7 @@ def from_db
end

should "allow to add new keys" do
entries = OpenStruct.new()
entries = MongoidExt::OpenStruct.new()
entries.new_key = "my new key"
@config.entries = entries
@config.save
Expand Down

0 comments on commit 14267b0

Please sign in to comment.