Class: ApiResource::Associations::MultiObjectProxy
- Inherits:
-
AssociationProxy
show all
- Includes:
- Enumerable
- Defined in:
- lib/api_resource/associations/multi_object_proxy.rb
Instance Attribute Summary
#finder_opts, #klass, #owner, #remote_path
Instance Method Summary
collapse
define_association_as_attribute, #expires_in, #includes, #initialize, #load_resource_definition, #loaded?, #reload, #ttl
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ApiResource::Associations::AssociationProxy
Instance Method Details
#==(other) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/api_resource/associations/multi_object_proxy.rb', line 66
def ==(other)
return false if self.class != other.class
if self.internal_object.is_a?(Array)
self.internal_object.sort.each_with_index do |elem, i|
return false if other.internal_object.sort[i].attributes != elem.attributes
end
end
return true
end
|
#all ⇒ Object
9
10
11
|
# File 'lib/api_resource/associations/multi_object_proxy.rb', line 9
def all
self.internal_object
end
|
#collection? ⇒ Boolean
13
14
15
|
# File 'lib/api_resource/associations/multi_object_proxy.rb', line 13
def collection?
true
end
|
#each(*args, &block) ⇒ Object
17
18
19
|
# File 'lib/api_resource/associations/multi_object_proxy.rb', line 17
def each(*args, &block)
self.internal_object.each(*args, &block)
end
|
#internal_object ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/api_resource/associations/multi_object_proxy.rb', line 21
def internal_object
if self.remote_path.blank? && @internal_object.blank?
return @internal_object ||= []
end
if !self.loaded? && @internal_object.blank?
@internal_object = self.load
end
@internal_object
end
|
#internal_object=(contents) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/api_resource/associations/multi_object_proxy.rb', line 36
def internal_object=(contents)
unless self.remote_path.present?
return true if self.set_remote_path(contents)
end
if contents.try(:first).is_a?(self.klass)
@loaded = true
return @internal_object = contents
elsif contents.instance_of?(self.class)
@loaded = true
return @internal_object = contents.internal_object
elsif contents.is_a?(Array)
@loaded = true
return @internal_object = self.klass.instantiate_collection(
contents
)
elsif contents.nil?
return @internal_object = []
else
raise ArgumentError.new(
"#{contents} must be a #{self.klass}, #{self.class}, " +
"Array or nil"
)
end
end
|
#serializable_hash(options) ⇒ Object
76
77
78
|
# File 'lib/api_resource/associations/multi_object_proxy.rb', line 76
def serializable_hash(options)
self.internal_object.collect{|obj| obj.serializable_hash(options) }
end
|