Class: Cot::Collection
Instance Attribute Summary
#klass, #options
Instance Method Summary
collapse
collected_class, set_default_values
Constructor Details
#initialize(*params) ⇒ Collection
We take an array of params here and then parse them due to backwards compat crap Collection can take 1-3 parameters and there are two cases when it gets two 3: klass, objects, options 2: klass, objects 2: objects, options 1: objects
11
12
13
14
15
16
17
18
|
# File 'lib/cot/collection.rb', line 11
def initialize(*params)
parse_params(params)
initialize_objects(@objects) unless @objects.first.instance_of? self.class.klass
super @objects
end
|
Instance Method Details
#changed? ⇒ Boolean
41
42
43
|
# File 'lib/cot/collection.rb', line 41
def changed?
map(&:changed?).include? true
end
|
#errors ⇒ Object
32
33
34
|
# File 'lib/cot/collection.rb', line 32
def errors
Hash[reject(&:valid?).map { |x| [x.id, x.errors] }]
end
|
#exists? ⇒ Boolean
28
29
30
|
# File 'lib/cot/collection.rb', line 28
def exists?
map(&:exists?).all?
end
|
#serializable_hash ⇒ Object
20
21
22
|
# File 'lib/cot/collection.rb', line 20
def serializable_hash
map(&:serializable_hash)
end
|
#to_json ⇒ Object
24
25
26
|
# File 'lib/cot/collection.rb', line 24
def to_json
serializable_hash.to_json
end
|
#update_members(payload) ⇒ Object
36
37
38
39
|
# File 'lib/cot/collection.rb', line 36
def update_members(payload)
initialize_objects(payload)
end
|