added possibility to cast any key to any type using any method
This commit is contained in:
parent
12c09085df
commit
716bc74023
2 changed files with 23 additions and 4 deletions
|
@ -537,13 +537,14 @@ module CouchRest
|
|||
self.class.casts.each do |k,v|
|
||||
next unless self[k]
|
||||
target = v[:as]
|
||||
v[:send] ||= 'new'
|
||||
if target.is_a?(Array)
|
||||
klass = ::Extlib::Inflection.constantize(target[0])
|
||||
self[k] = self[k].collect do |value|
|
||||
klass.new(value)
|
||||
klass.send(v[:send], value)
|
||||
end
|
||||
else
|
||||
self[k] = ::Extlib::Inflection.constantize(target).new(self[k])
|
||||
self[k] = ::Extlib::Inflection.constantize(target).send(v[:send], self[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -554,4 +555,4 @@ module CouchRest
|
|||
register_instance_hooks :save, :create, :update, :destroy
|
||||
|
||||
end # class Model
|
||||
end # module CouchRest
|
||||
end # module CouchRest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue