Class: Sequencescape::Api::Associations::HasMany::AssociationProxy

Inherits:
Base
  • Object
show all
Extended by:
Sequencescape::Api::Actions
Includes:
Enumerable, Json, Validation, FinderMethods, FinderMethods::Caching
Defined in:
lib/sequencescape-api/associations/has_many.rb

Instance Method Summary collapse

Methods included from Sequencescape::Api::Actions

extended

Methods included from Validation

#errors, #run_validations!

Methods included from Json

#as_json, included

Methods included from FinderMethods::Caching

#all

Methods included from FinderMethods

#all, extended, #find, included

Methods included from Base::InstanceMethods

included, #proxy_present?

Constructor Details

#initialize(owner, json = nil) ⇒ AssociationProxy

Returns a new instance of AssociationProxy.



33
34
35
36
37
38
# File 'lib/sequencescape-api/associations/has_many.rb', line 33

def initialize(owner, json = nil)
  super
  @cached_all = case json
                when Array then json.map { |js| new_from(js) }
                end
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/sequencescape-api/associations/has_many.rb', line 23

def empty?
  return @_attributes_['size'].zero? if api.capabilities.size_in_pages?

  all.empty?
end

#new_from(json) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/sequencescape-api/associations/has_many.rb', line 40

def new_from(json)
  case json
  when String then new(uuid: json) # We've recieved an array of strings, prob. uuids
  when Hash then new(json)
  else json
  end
end

#present?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/sequencescape-api/associations/has_many.rb', line 29

def present?
  !empty?
end

#sizeObject



17
18
19
20
21
# File 'lib/sequencescape-api/associations/has_many.rb', line 17

def size
  return @_attributes_['size'] if api.capabilities.size_in_pages?

  all.size
end

#update_from_json(_) ⇒ Object



48
49
50
# File 'lib/sequencescape-api/associations/has_many.rb', line 48

def update_from_json(_)
  @cached_all = nil
end