Class: Dynamoid::Transactions::Retrieval::Find

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/transactions/retrieval/find.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class, *ids, **options) ⇒ Find

Returns a new instance of Find.



10
11
12
13
14
# File 'lib/dynamoid/transactions/retrieval/find.rb', line 10

def initialize(model_class, *ids, **options)
  @model_class = model_class
  @ids = ids
  @options = options
end

Instance Attribute Details

#model_classObject (readonly)

Returns the value of attribute model_class.



8
9
10
# File 'lib/dynamoid/transactions/retrieval/find.rb', line 8

def model_class
  @model_class
end

Instance Method Details

#action_requestObject



24
25
26
27
28
29
30
# File 'lib/dynamoid/transactions/retrieval/find.rb', line 24

def action_request
  if single_key_given?
    action_request_for_single_key
  else
    action_request_for_multiple_keys
  end
end

#observable_by_user_resultObject



20
21
22
# File 'lib/dynamoid/transactions/retrieval/find.rb', line 20

def observable_by_user_result
  nil
end

#on_registrationObject



16
17
18
# File 'lib/dynamoid/transactions/retrieval/find.rb', line 16

def on_registration
  validate_primary_key!
end

#process_responses(responses) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dynamoid/transactions/retrieval/find.rb', line 32

def process_responses(responses)
  models = responses.map do |response|
    if response.item
      @model_class.from_database(response.item)
    elsif @options[:raise_error] == false
      nil
    else
      message = build_record_not_found_exception_message(responses)
      raise Dynamoid::Errors::RecordNotFound, message
    end
  end

  unless single_key_given?
    models.compact!
  end

  models.each { |m| m&.run_callbacks :find }
  models
end