Clear the instance filters after successfully destroying the object.
# File lib/sequel/plugins/instance_filters.rb, line 51 def after_destroy super clear_instance_filters end
Clear the instance filters after successfully updating the object.
# File lib/sequel/plugins/instance_filters.rb, line 57 def after_update super clear_instance_filters end
Freeze the instance filters when freezing the object
# File lib/sequel/plugins/instance_filters.rb, line 63 def freeze instance_filters.freeze super end
Add an instance filter to the array of instance filters Both the arguments given and the block are passed to the dataset's filter method.
# File lib/sequel/plugins/instance_filters.rb, line 71 def instance_filter(*args, &block) instance_filters << [args, block] end
Apply the instance filters to the dataset returned by super.
# File lib/sequel/plugins/instance_filters.rb, line 103 def _delete_dataset apply_instance_filters(super) end
If there are any instance filters, make sure not to use the instance delete optimization.
# File lib/sequel/plugins/instance_filters.rb, line 79 def _delete_without_checking if @instance_filters && !@instance_filters.empty? _delete_dataset.delete else super end end
Apply the instance filters to the dataset returned by super.
# File lib/sequel/plugins/instance_filters.rb, line 108 def _update_dataset apply_instance_filters(super) end
Apply the instance filters to the given dataset
# File lib/sequel/plugins/instance_filters.rb, line 93 def apply_instance_filters(ds) instance_filters.inject(ds){|ds1, i| ds1.filter(*i[0], &i[1])} end
Clear the instance filters.
# File lib/sequel/plugins/instance_filters.rb, line 98 def clear_instance_filters instance_filters.clear end
Lazily initialize the instance filter array.
# File lib/sequel/plugins/instance_filters.rb, line 88 def instance_filters @instance_filters ||= [] end