module Sequel::Plugins::InstanceFilters::InstanceMethods
Public Instance Methods
Source
# 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 destroying the object.
Source
# File lib/sequel/plugins/instance_filters.rb 61 def after_update 62 super 63 clear_instance_filters 64 end
Clear the instance filters after successfully updating the object.
Source
# File lib/sequel/plugins/instance_filters.rb 67 def freeze 68 instance_filters.freeze 69 super 70 end
Freeze the instance filters when freezing the object
Source
# File lib/sequel/plugins/instance_filters.rb 75 def instance_filter(*args, &block) 76 instance_filters << [args, block] 77 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 117 def _delete_dataset 118 apply_instance_filters(super) 119 end
Apply the instance filters to the dataset returned by super.
Source
# 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
If there are any instance filters, make sure not to use the instance delete optimization.
Source
# File lib/sequel/plugins/instance_filters.rb 122 def _update_dataset 123 apply_instance_filters(super) 124 end
Apply the instance filters to the dataset returned by super.
Source
# File lib/sequel/plugins/instance_filters.rb 104 def apply_instance_filters(ds) 105 instance_filters.inject(ds) do |ds1, i| 106 block = i[1] 107 ds1.where(*i[0], &block) 108 end 109 end
Apply the instance filters to the given dataset
Source
# File lib/sequel/plugins/instance_filters.rb 112 def clear_instance_filters 113 instance_filters.clear 114 end
Clear the instance filters.
Source
# 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
Duplicate internal structures when duplicating model instance.
Source
# File lib/sequel/plugins/instance_filters.rb 99 def instance_filters 100 @instance_filters ||= [] 101 end
Lazily initialize the instance filter array.
Source
# File lib/sequel/plugins/instance_filters.rb 128 def use_prepared_statements_for?(type) 129 if type == :update && !instance_filters.empty? 130 false 131 else 132 super if defined?(super) 133 end 134 end
Only use prepared statements for update and delete queries if there are no instance filters.