Class: CouchRest::Model::CastedArray

Inherits:
Array
  • Object
show all
Includes:
CastedBy, Dirty
Defined in:
lib/couchrest/model/casted_array.rb

Direct Known Subclasses

CollectionOfProxy

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Dirty

#couchrest_attribute_will_change!, #couchrest_parent_will_change!, #use_dirty?

Methods included from CastedBy

#base_doc, #base_doc?

Constructor Details

- (CastedArray) initialize(array, property, parent = nil)



12
13
14
15
16
# File 'lib/couchrest/model/casted_array.rb', line 12

def initialize(array, property, parent = nil)
  self.casted_by_property = property
  self.casted_by = parent unless parent.nil?
  super(array)
end

Instance Attribute Details

- (Object) casted_by_property

Returns the value of attribute casted_by_property



10
11
12
# File 'lib/couchrest/model/casted_array.rb', line 10

def casted_by_property
  @casted_by_property
end

Instance Method Details

- (Object) <<(obj)

Adding new entries



20
21
22
# File 'lib/couchrest/model/casted_array.rb', line 20

def << obj
  super(instantiate_and_cast(obj))
end

- (Object) []=(index, obj)



32
33
34
35
36
# File 'lib/couchrest/model/casted_array.rb', line 32

def []= index, obj
  value = instantiate_and_cast(obj, false)
  couchrest_parent_will_change! if use_dirty? && value != self[index]
  super(index, value)
end

- (Object) build(*args)



63
64
65
66
67
# File 'lib/couchrest/model/casted_array.rb', line 63

def build(*args)
  obj = casted_by_property.build(*args)
  self.push(obj)
  obj
end

- (Object) clear



48
49
50
51
# File 'lib/couchrest/model/casted_array.rb', line 48

def clear
  couchrest_parent_will_change! if use_dirty? && self.length > 0
  super
end

- (Object) delete(obj)



53
54
55
56
# File 'lib/couchrest/model/casted_array.rb', line 53

def delete(obj)
  couchrest_parent_will_change! if use_dirty? && self.length > 0
  super(obj)
end

- (Object) delete_at(index)



58
59
60
61
# File 'lib/couchrest/model/casted_array.rb', line 58

def delete_at(index)
  couchrest_parent_will_change! if use_dirty? && self.length > 0
  super(index)
end

- (Object) pop



38
39
40
41
# File 'lib/couchrest/model/casted_array.rb', line 38

def pop
  couchrest_parent_will_change! if use_dirty? && self.length > 0
  super
end

- (Object) push(obj)



24
25
26
# File 'lib/couchrest/model/casted_array.rb', line 24

def push(obj)
  super(instantiate_and_cast(obj))
end

- (Object) shift



43
44
45
46
# File 'lib/couchrest/model/casted_array.rb', line 43

def shift
  couchrest_parent_will_change! if use_dirty? && self.length > 0
  super
end

- (Object) unshift(obj)



28
29
30
# File 'lib/couchrest/model/casted_array.rb', line 28

def unshift(obj)
  super(instantiate_and_cast(obj))
end