Module: ActiveRemote::Bulk::ClassMethods
- Defined in:
- lib/active_remote/bulk.rb
Instance Method Summary collapse
-
#create_all(*records) ⇒ Object
Create multiple records at the same time.
-
#delete_all(*records) ⇒ Object
Delete multiple records at the same time.
-
#destroy_all(*records) ⇒ Object
Destroy multiple records at the same time.
-
#parse_records(*records) ⇒ Object
Parse given records to get them ready to be built into a request.
-
#update_all(*records) ⇒ Object
Update multiple records at the same time.
Instance Method Details
#create_all(*records) ⇒ Object
Create multiple records at the same time. Returns a collection of active remote objects from the passed records. Records that were not created are returned with error messages indicating what went wrong.
Examples
# A single hash
Tag.create_all({ :name => 'foo' })
# Hashes
Tag.create_all({ :name => 'foo' }, { :name => 'bar' })
# Active remote objects
Tag.create_all(Tag.new(:name => 'foo'), Tag.new(:name => 'bar'))
# Protobuf objects
Tag.create_all(Generic::Remote::Tag.new(:name => 'foo'), Generic::Remote::Tag.new(:name => 'bar'))
# Bulk protobuf object
Tag.create_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:name => 'foo') ])
34 35 36 37 38 39 40 41 42 |
# File 'lib/active_remote/bulk.rb', line 34 def create_all(*records) response = rpc.execute(:create_all, _parse_records(records)) if response.respond_to?(:records) serialize_records(response.records) else warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception" end end |
#delete_all(*records) ⇒ Object
Delete multiple records at the same time. Returns a collection of active remote objects from the passed records. Records that were not deleted are returned with error messages indicating what went wrong.
Examples
# A single hash
Tag.delete_all({ :guid => 'foo' })
# Hashes
Tag.delete_all({ :guid => 'foo' }, { :guid => 'bar' })
# Active remote objects
Tag.delete_all(Tag.new(:guid => 'foo'), Tag.new(:guid => 'bar'))
# Protobuf objects
Tag.delete_all(Generic::Remote::Tag.new(:guid => 'foo'), Generic::Remote::Tag.new(:guid => 'bar'))
# Bulk protobuf object
Tag.delete_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
65 66 67 68 69 70 71 72 73 |
# File 'lib/active_remote/bulk.rb', line 65 def delete_all(*records) response = rpc.execute(:delete_all, _parse_records(records)) if response.respond_to?(:records) serialize_records(response.records) else warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception" end end |
#destroy_all(*records) ⇒ Object
Destroy multiple records at the same time. Returns a collection of active remote objects from the passed records. Records that were not destroyed are returned with error messages indicating what went wrong.
Examples
# A single hash
Tag.destroy_all({ :guid => 'foo' })
# Hashes
Tag.destroy_all({ :guid => 'foo' }, { :guid => 'bar' })
# Active remote objects
Tag.destroy_all(Tag.new(:guid => 'foo'), Tag.new(:guid => 'bar'))
# Protobuf objects
Tag.destroy_all(Generic::Remote::Tag.new(:guid => 'foo'), Generic::Remote::Tag.new(:guid => 'bar'))
# Bulk protobuf object
Tag.destroy_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
96 97 98 99 100 101 102 103 104 |
# File 'lib/active_remote/bulk.rb', line 96 def destroy_all(*records) response = rpc.execute(:destroy_all, _parse_records(records)) if response.respond_to?(:records) serialize_records(response.records) else warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception" end end |
#parse_records(*records) ⇒ Object
Parse given records to get them ready to be built into a request.
It handles any object that responds to to_hash, so protobuf messages and active remote objects will work just like hashes.
Returns { :records => records }.
113 114 115 116 117 |
# File 'lib/active_remote/bulk.rb', line 113 def parse_records(*records) warn "DEPRECATED Model.parse_records is deprecated. It will be removed in Active Remove 3.0" _parse_records(*records) end |
#update_all(*records) ⇒ Object
Update multiple records at the same time. Returns a collection of active remote objects from the passed records. Records that were not updated are returned with error messages indicating what went wrong.
Examples
# A single hash
Tag.update_all({ :guid => 'foo', :name => 'baz' })
# Hashes
Tag.update_all({ :guid => 'foo', :name => 'baz' }, { :guid => 'bar', :name => 'qux' })
# Active remote objects
Tag.update_all(Tag.new(:guid => 'foo', :name => 'baz'), Tag.new(:guid => 'bar', :name => 'qux'))
# Protobuf objects
Tag.update_all(Generic::Remote::Tag.new(:guid => 'foo', :name => 'baz'), Generic::Remote::Tag.new(:guid => 'bar', :name => 'qux'))
# Bulk protobuf object
Tag.update_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo', :name => 'baz') ])
140 141 142 143 144 145 146 147 148 |
# File 'lib/active_remote/bulk.rb', line 140 def update_all(*records) response = rpc.execute(:update_all, _parse_records(records)) if response.respond_to?(:records) serialize_records(response.records) else warn "DEPRECATED responses to bulk methods must respond to :records. In Active Remote 3.0, bulk responses that don't respond to :records will raise an exception" end end |