module RailsRbs::RunsAction
Public Instance Methods
apply(*objects)
click to toggle source
Apply the action to all objects in the provided collection. Application simply means the enforced_field will be set to the enforced_value. @param objects [Array<ActiveRecord::BAse> | ActiveRecord::Base] a single collection of active record objects to have this rule_action applied to.
# File lib/rails_rbs/runs_action.rb, line 15 def apply(*objects) objects.flatten.map do |object| if object.persisted? response = object.update_column(self.enforced_field.to_sym, self.enforced_value) else response = object.send("#{self.enforced_field.to_sym}=", self.enforced_value) end [response, object.try(:errors)] end end