Class: Gcloud::Bigquery::InsertResponse
- Inherits:
-
Object
- Object
- Gcloud::Bigquery::InsertResponse
- Defined in:
- lib/gcloud/bigquery/insert_response.rb
Overview
InsertResponse
Defined Under Namespace
Classes: InsertError
Class Method Summary collapse
Instance Method Summary collapse
- #error_count ⇒ Object
- #error_rows ⇒ Object
- #errors_for(row) ⇒ Object
-
#initialize(rows, gapi) ⇒ InsertResponse
constructor
A new instance of InsertResponse.
- #insert_count ⇒ Object
- #insert_errors ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(rows, gapi) ⇒ InsertResponse
Returns a new instance of InsertResponse.
22 23 24 25 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 22 def initialize rows, gapi @rows = rows @gapi = gapi end |
Class Method Details
.from_gapi(rows, gapi) ⇒ Object
64 65 66 67 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 64 def self.from_gapi rows, gapi gapi = gapi.to_hash if gapi.respond_to? :to_hash new rows, gapi end |
Instance Method Details
#error_count ⇒ Object
35 36 37 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 35 def error_count @error_count ||= Array(@gapi["insertErrors"]).count end |
#error_rows ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 49 def error_rows @error_rows ||= begin Array(@gapi["insertErrors"]).map do |ie| @rows[ie["index"]] end end end |
#errors_for(row) ⇒ Object
57 58 59 60 61 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 57 def errors_for row ie = insert_errors.detect { |e| e.row == row } return ie.errors if ie [] end |
#insert_count ⇒ Object
31 32 33 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 31 def insert_count @insert_count ||= @rows.count - error_count end |
#insert_errors ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 39 def insert_errors @insert_errors ||= begin Array(@gapi["insertErrors"]).map do |ie| row = @rows[ie["index"]] errors = ie["errors"] InsertError.new row, errors end end end |
#success? ⇒ Boolean
27 28 29 |
# File 'lib/gcloud/bigquery/insert_response.rb', line 27 def success? error_count.zero? end |