Module: Railsmith::BaseService::BulkActions Private
- Includes:
- BulkContract, BulkExecution, BulkParams
- Included in:
- Railsmith::BaseService
- Defined in:
- lib/railsmith/base_service/bulk_actions.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Default bulk action implementations.
Constant Summary
Constants included from BulkParams
Railsmith::BaseService::BulkParams::DEFAULT_BATCH_SIZE, Railsmith::BaseService::BulkParams::DEFAULT_BULK_LIMIT, Railsmith::BaseService::BulkParams::TRANSACTION_MODE_ALL_OR_NOTHING, Railsmith::BaseService::BulkParams::TRANSACTION_MODE_BEST_EFFORT
Instance Method Summary collapse
- #bulk_create ⇒ Object private
- #bulk_destroy ⇒ Object private
- #bulk_update ⇒ Object private
Instance Method Details
#bulk_create ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/railsmith/base_service/bulk_actions.rb', line 12 def bulk_create model_klass = model_class return missing_model_class_result unless model_klass has_assocs = self.class.respond_to?(:association_registry) && self.class.association_registry.any? bulk_write_operation(model_klass, operation: :bulk_create) do |item| # Support both flat attribute hashes ({ name: "A" }) and the # nested format ({ attributes: { name: "A" }, line_items: [...] }). attrs = bulk_item_attributes(item) record = build_record(model_klass, sanitize_attributes(attrs)) result = persist_write(record, method_name: :save) next result if result.failure? || !has_assocs write_nested_for_item(record, item, :create) end end |
#bulk_destroy ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 44 45 46 |
# File 'lib/railsmith/base_service/bulk_actions.rb', line 39 def bulk_destroy model_klass = model_class return missing_model_class_result unless model_klass bulk_write_operation(model_klass, operation: :bulk_destroy) do |item| bulk_destroy_one(model_klass, item) end end |
#bulk_update ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 36 37 |
# File 'lib/railsmith/base_service/bulk_actions.rb', line 30 def bulk_update model_klass = model_class return missing_model_class_result unless model_klass bulk_write_operation(model_klass, operation: :bulk_update) do |item| bulk_update_one(model_klass, item) end end |