Class: PinFlags::FeatureSubscription::BulkProcessor
- Inherits:
-
Object
- Object
- PinFlags::FeatureSubscription::BulkProcessor
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Validations
- Defined in:
- app/models/pin_flags/feature_subscription/bulk_processor.rb
Instance Attribute Summary collapse
-
#feature_taggable_ids ⇒ Object
Returns the value of attribute feature_taggable_ids.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ BulkProcessor
constructor
A new instance of BulkProcessor.
- #process ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ BulkProcessor
Returns a new instance of BulkProcessor.
17 18 19 20 |
# File 'app/models/pin_flags/feature_subscription/bulk_processor.rb', line 17 def initialize(attributes = {}) super @feature_taggable_ids = Array(attributes[:feature_taggable_ids]) if attributes[:feature_taggable_ids] end |
Instance Attribute Details
#feature_taggable_ids ⇒ Object
Returns the value of attribute feature_taggable_ids.
9 10 11 |
# File 'app/models/pin_flags/feature_subscription/bulk_processor.rb', line 9 def feature_taggable_ids @feature_taggable_ids end |
Instance Method Details
#process ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/pin_flags/feature_subscription/bulk_processor.rb', line 22 def process return false unless valid? # Prepare records for upsert_all records = sanitized_feature_taggable_ids.map do |feature_taggable_id| { feature_tag_id: feature_tag.id, feature_taggable_type: feature_taggable_type, feature_taggable_id: feature_taggable_id, created_at: Time.current, updated_at: Time.current } end begin # Use upsert_all to insert or update records in bulk PinFlags::FeatureSubscription.upsert_all( records, unique_by: [ :feature_tag_id, :feature_taggable_type, :feature_taggable_id ] ) true rescue ActiveRecord::RecordInvalid, ActiveRecord::StatementInvalid => _e false end end |