class CouchRest::CastedArray

Attributes

casted_by[RW]
property[RW]

Public Instance Methods

<<(obj) click to toggle source
# File lib/couchrest/casted_array.rb, line 16
def << obj
  super(instantiate_and_cast(obj))
end
[]=(index, obj) click to toggle source
# File lib/couchrest/casted_array.rb, line 24
def []= index, obj
  super(index, instantiate_and_cast(obj))
end
push(obj) click to toggle source
# File lib/couchrest/casted_array.rb, line 20
def push(obj)
  super(instantiate_and_cast(obj))
end

Protected Instance Methods

instantiate_and_cast(obj) click to toggle source
# File lib/couchrest/casted_array.rb, line 30
def instantiate_and_cast(obj)
  if self.casted_by && self.property && obj.class != self.property.type_class
    self.property.cast_value(self.casted_by, obj)
  else
    obj.casted_by = self.casted_by if obj.respond_to?(:casted_by)
    obj
  end
end

Public Class Methods

new(array, property) click to toggle source
# File lib/couchrest/casted_array.rb, line 11
def initialize(array, property)
  self.property = property
  super(array)
end