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.



59
60
61
62
63
64
65
66
67
# File 'lib/sequencescape-api/associations/has_many.rb', line 59

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



89
90
91
# File 'lib/sequencescape-api/associations/has_many.rb', line 89

def all
  @objects
end

#changed?Boolean

We are changed if any of our objects have been changed.

Returns:

  • (Boolean)


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

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

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

Yields:

  • (@objects)


93
94
95
# File 'lib/sequencescape-api/associations/has_many.rb', line 93

def each_page(&block)
  yield(@objects)
end

#find(uuid) ⇒ Object



85
86
87
# File 'lib/sequencescape-api/associations/has_many.rb', line 85

def find(uuid)
  @objects.detect { |o| o.uuid == uuid }
end