Class: Sequencescape::Api::Associations::HasMany::InlineAssociationProxy
Instance Method Summary
collapse
Methods included from Validation
#errors, #run_validations!
Methods included from Json
#as_json, included
included, #proxy_present?
included
Constructor Details
Returns a new instance of InlineAssociationProxy.
60
61
62
63
64
65
66
67
68
|
# File 'lib/sequencescape-api/associations/has_many.rb', line 60
def initialize(owner, json = nil)
super
@objects =
case
when @_attributes_.is_a?(Array) then @_attributes_.map(&method(:new))
when @_attributes_.is_a?(Hash) then @_attributes_.map { |uuid, json| new(json.merge('uuid' => uuid)) }
else raise StandardError, "Cannot handle has_many JSON: #{json.inspect}"
end
end
|
Instance Method Details
#all ⇒ Object
90
91
92
|
# File 'lib/sequencescape-api/associations/has_many.rb', line 90
def all
@objects
end
|
#changed? ⇒ Boolean
We are changed if any of our objects have been changed.
104
105
106
|
# File 'lib/sequencescape-api/associations/has_many.rb', line 104
def changed?
@objects.any?(&:changed?)
end
|
#each_page {|@objects| ... } ⇒ Object
94
95
96
|
# File 'lib/sequencescape-api/associations/has_many.rb', line 94
def each_page
yield(@objects)
end
|
#find(uuid) ⇒ Object
86
87
88
|
# File 'lib/sequencescape-api/associations/has_many.rb', line 86
def find(uuid)
@objects.detect { |o| o.uuid == uuid }
end
|