module Sequel::Plugins::InstanceFilters::InstanceMethods
Public Instance Methods
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
Private Instance Methods
Apply the instance filters to the dataset returned by super.
# File lib/sequel/plugins/instance_filters.rb, line 110 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 115 def _update_dataset apply_instance_filters(super) end
Apply the instance filters to the given dataset
# File lib/sequel/plugins/instance_filters.rb, line 100 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 105 def clear_instance_filters instance_filters.clear end
Duplicate internal structures when duplicating model instance.
# File lib/sequel/plugins/instance_filters.rb, line 88 def initialize_copy(other) super @instance_filters = other.send(:instance_filters).dup self end
Lazily initialize the instance filter array.
# File lib/sequel/plugins/instance_filters.rb, line 95 def instance_filters @instance_filters ||= [] end
Only use prepared statements for update and delete queries if there are no instance filters.
# File lib/sequel/plugins/instance_filters.rb, line 121 def use_prepared_statements_for?(type) if (type == :update || type == :delete) && !instance_filters.empty? false else super end end