module Sequel::Plugins::InstanceFilters::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/instance_filters.rb 59 def after_destroy 60 super 61 clear_instance_filters 62 end
Clear the instance filters after successfully destroying the object.
Source
# File lib/sequel/plugins/instance_filters.rb 65 def after_update 66 super 67 clear_instance_filters 68 end
Clear the instance filters after successfully updating the object.
Source
# File lib/sequel/plugins/instance_filters.rb 71 def freeze 72 instance_filters.freeze 73 super 74 end
Freeze the instance filters when freezing the object
Source
# File lib/sequel/plugins/instance_filters.rb 79 def instance_filter(*args, &block) 80 instance_filters << [args, block] 81 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.
Private Instance Methods
Source
# File lib/sequel/plugins/instance_filters.rb 121 def _delete_dataset 122 apply_instance_filters(super) 123 end
Apply the instance filters to the dataset returned by super.
Source
# File lib/sequel/plugins/instance_filters.rb 87 def _delete_without_checking 88 if @instance_filters && !@instance_filters.empty? 89 _delete_dataset.delete 90 else 91 super 92 end 93 end
If there are any instance filters, make sure not to use the instance delete optimization.
Source
# File lib/sequel/plugins/instance_filters.rb 126 def _update_dataset 127 apply_instance_filters(super) 128 end
Apply the instance filters to the dataset returned by super.
Source
# File lib/sequel/plugins/instance_filters.rb 108 def apply_instance_filters(ds) 109 instance_filters.inject(ds) do |ds1, i| 110 block = i[1] 111 ds1.where(*i[0], &block) 112 end 113 end
Apply the instance filters to the given dataset
Source
# File lib/sequel/plugins/instance_filters.rb 116 def clear_instance_filters 117 instance_filters.clear 118 end
Clear the instance filters.
Source
# File lib/sequel/plugins/instance_filters.rb 96 def initialize_copy(other) 97 super 98 @instance_filters = other.send(:instance_filters).dup 99 self 100 end
Duplicate internal structures when duplicating model instance.
Source
# File lib/sequel/plugins/instance_filters.rb 103 def instance_filters 104 @instance_filters ||= [] 105 end
Lazily initialize the instance filter array.
Source
# File lib/sequel/plugins/instance_filters.rb 132 def use_prepared_statements_for?(type) 133 if type == :update && !instance_filters.empty? 134 false 135 else 136 super if defined?(super) 137 end 138 end
Only use prepared statements for update and delete queries if there are no instance filters.