Class: Sequencescape::Api::Associations::HasMany::InlineAssociationProxy

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Base::InstanceMethods, Json, Validation, FinderMethods::Delegation
Defined in:
lib/sequencescape-api/associations/has_many.rb

Instance Method Summary collapse

Methods included from Validation

#errors, #run_validations!

Methods included from Json

#as_json, included

Methods included from Base::InstanceMethods

included, #proxy_present?

Methods included from FinderMethods::Delegation

included

Constructor Details

#initialize(owner, json = nil) ⇒ InlineAssociationProxy

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

#allObject



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.

Returns:

  • (Boolean)


104
105
106
# File 'lib/sequencescape-api/associations/has_many.rb', line 104

def changed?
  @objects.any?(&:changed?)
end

#each_page {|@objects| ... } ⇒ Object

Yields:

  • (@objects)


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