Class: Dynamoid::TransactionRead::Find

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Find.



8
9
10
11
12
# File 'lib/dynamoid/transaction_read/find.rb', line 8

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.



6
7
8
# File 'lib/dynamoid/transaction_read/find.rb', line 6

def model_class
  @model_class
end

Instance Method Details

#action_requestObject



22
23
24
25
26
27
28
# File 'lib/dynamoid/transaction_read/find.rb', line 22

def action_request
  if single_key_given?
    action_request_for_single_key
  else
    action_request_for_multiple_keys
  end
end

#observable_by_user_resultObject



18
19
20
# File 'lib/dynamoid/transaction_read/find.rb', line 18

def observable_by_user_result
  nil
end

#on_registrationObject



14
15
16
# File 'lib/dynamoid/transaction_read/find.rb', line 14

def on_registration
  validate_primary_key!
end

#process_responses(responses) ⇒ Object



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

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