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.
Source
# File lib/sequel/plugins/instance_filters.rb 85 def save_changes(opts=OPTS) 86 ret = super 87 clear_instance_filters if ret.nil? 88 ret 89 end
Clear instance filters when saving changes even if the object wasn’t modified.
Private Instance Methods
Source
# File lib/sequel/plugins/instance_filters.rb 129 def _delete_dataset 130 apply_instance_filters(super) 131 end
Apply the instance filters to the dataset returned by super.
Source
# File lib/sequel/plugins/instance_filters.rb 95 def _delete_without_checking 96 if @instance_filters && !@instance_filters.empty? 97 _delete_dataset.delete 98 else 99 super 100 end 101 end
If there are any instance filters, make sure not to use the instance delete optimization.
Source
# File lib/sequel/plugins/instance_filters.rb 134 def _update_dataset 135 apply_instance_filters(super) 136 end
Apply the instance filters to the dataset returned by super.
Source
# File lib/sequel/plugins/instance_filters.rb 116 def apply_instance_filters(ds) 117 instance_filters.inject(ds) do |ds1, i| 118 block = i[1] 119 ds1.where(*i[0], &block) 120 end 121 end
Apply the instance filters to the given dataset
Source
# File lib/sequel/plugins/instance_filters.rb 124 def clear_instance_filters 125 instance_filters.clear 126 end
Clear the instance filters.
Source
# File lib/sequel/plugins/instance_filters.rb 104 def initialize_copy(other) 105 super 106 @instance_filters = other.send(:instance_filters).dup 107 self 108 end
Duplicate internal structures when duplicating model instance.
Source
# File lib/sequel/plugins/instance_filters.rb 111 def instance_filters 112 @instance_filters ||= [] 113 end
Lazily initialize the instance filter array.
Source
# File lib/sequel/plugins/instance_filters.rb 140 def use_prepared_statements_for?(type) 141 if type == :update && !instance_filters.empty? 142 false 143 else 144 super if defined?(super) 145 end 146 end
Only use prepared statements for update and delete queries if there are no instance filters.