module Sequel::Plugins::InstanceFilters::InstanceMethods
Public Instance Methods
Clear the instance filters after successfully destroying the object.
# File lib/sequel/plugins/instance_filters.rb 55 def after_destroy 56 super 57 clear_instance_filters 58 end
Clear the instance filters after successfully updating the object.
# File lib/sequel/plugins/instance_filters.rb 61 def after_update 62 super 63 clear_instance_filters 64 end
Freeze the instance filters when freezing the object
# File lib/sequel/plugins/instance_filters.rb 67 def freeze 68 instance_filters.freeze 69 super 70 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 75 def instance_filter(*args, &block) 76 instance_filters << [args, block] 77 end
Private Instance Methods
Apply the instance filters to the dataset returned by super.
# File lib/sequel/plugins/instance_filters.rb 114 def _delete_dataset 115 apply_instance_filters(super) 116 end
If there are any instance filters, make sure not to use the instance delete optimization.
# File lib/sequel/plugins/instance_filters.rb 83 def _delete_without_checking 84 if @instance_filters && !@instance_filters.empty? 85 _delete_dataset.delete 86 else 87 super 88 end 89 end
Apply the instance filters to the dataset returned by super.
# File lib/sequel/plugins/instance_filters.rb 119 def _update_dataset 120 apply_instance_filters(super) 121 end
Apply the instance filters to the given dataset
# File lib/sequel/plugins/instance_filters.rb 104 def apply_instance_filters(ds) 105 instance_filters.inject(ds){|ds1, i| ds1.where(*i[0], &i[1])} 106 end
Clear the instance filters.
# File lib/sequel/plugins/instance_filters.rb 109 def clear_instance_filters 110 instance_filters.clear 111 end
Duplicate internal structures when duplicating model instance.
# File lib/sequel/plugins/instance_filters.rb 92 def initialize_copy(other) 93 super 94 @instance_filters = other.send(:instance_filters).dup 95 self 96 end
Lazily initialize the instance filter array.
# File lib/sequel/plugins/instance_filters.rb 99 def instance_filters 100 @instance_filters ||= [] 101 end
Only use prepared statements for update and delete queries if there are no instance filters.
# File lib/sequel/plugins/instance_filters.rb 125 def use_prepared_statements_for?(type) 126 if type == :update && !instance_filters.empty? 127 false 128 else 129 super if defined?(super) 130 end 131 end