lib/couchrest/model/casted_hash.rb in couchrest_model-1.1.0.beta3 vs lib/couchrest/model/casted_hash.rb in couchrest_model-1.1.0.beta4
- old
+ new
@@ -1,11 +1,19 @@
#
# Wrapper around Hash so that the casted_by attribute is set.
module CouchRest::Model
class CastedHash < Hash
+ include CouchRest::Model::CastedBy
include CouchRest::Model::Dirty
- attr_accessor :casted_by
+ attr_accessor :casted_by_property
+
+ def self.[](hash, property, parent = nil)
+ obj = super(hash)
+ obj.casted_by_property = property
+ obj.casted_by = parent unless parent.nil?
+ obj
+ end
# needed for dirty
def attributes
self
end