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
19
20
21
|
# File 'lib/cot/collection.rb', line 11
def initialize(*params)
parse_params(params)
if self.class.klass.nil?
fail 'Collected class not set, please either pass a class to initialize or call collected_class'
end
initialize_objects(@objects) unless @objects.first.instance_of? self.class.klass
super @objects
end
|
Instance Method Details
#changed? ⇒ Boolean
44
45
46
|
# File 'lib/cot/collection.rb', line 44
def changed?
map(&:changed?).include? true
end
|
#errors ⇒ Object
35
36
37
|
# File 'lib/cot/collection.rb', line 35
def errors
Hash[reject(&:valid?).map { |x| [x.id, x.errors] }]
end
|
#exists? ⇒ Boolean
31
32
33
|
# File 'lib/cot/collection.rb', line 31
def exists?
map(&:exists?).all?
end
|
#serializable_hash ⇒ Object
23
24
25
|
# File 'lib/cot/collection.rb', line 23
def serializable_hash
map(&:serializable_hash)
end
|
#to_json ⇒ Object
27
28
29
|
# File 'lib/cot/collection.rb', line 27
def to_json
serializable_hash.to_json
end
|
#update_members(payload) ⇒ Object
39
40
41
42
|
# File 'lib/cot/collection.rb', line 39
def update_members(payload)
initialize_objects(payload)
end
|