module Sequel::Plugins::InstanceFilters::InstanceMethods

Public Instance Methods

after_destroy() click to toggle source

Clear the instance filters after successfully destroying the object.

Calls superclass method
   # File lib/sequel/plugins/instance_filters.rb
59 def after_destroy
60   super
61   clear_instance_filters
62 end
after_update() click to toggle source

Clear the instance filters after successfully updating the object.

Calls superclass method
   # File lib/sequel/plugins/instance_filters.rb
65 def after_update
66   super
67   clear_instance_filters
68 end
freeze() click to toggle source

Freeze the instance filters when freezing the object

Calls superclass method
   # File lib/sequel/plugins/instance_filters.rb
71 def freeze
72   instance_filters.freeze
73   super
74 end
instance_filter(*args, &block) click to toggle source

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
79 def instance_filter(*args, &block)
80   instance_filters << [args, block]
81 end
save_changes(opts=OPTS) click to toggle source

Clear instance filters when saving changes even if the object wasn’t modified.

Calls superclass method
   # 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

Private Instance Methods

_delete_dataset() click to toggle source

Apply the instance filters to the dataset returned by super.

Calls superclass method
    # File lib/sequel/plugins/instance_filters.rb
129 def _delete_dataset
130   apply_instance_filters(super)
131 end
_delete_without_checking() click to toggle source

If there are any instance filters, make sure not to use the instance delete optimization.

Calls superclass method
    # 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
_update_dataset() click to toggle source

Apply the instance filters to the dataset returned by super.

Calls superclass method
    # File lib/sequel/plugins/instance_filters.rb
134 def _update_dataset
135   apply_instance_filters(super)
136 end
apply_instance_filters(ds) click to toggle source

Apply the instance filters to the given dataset

    # 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
clear_instance_filters() click to toggle source

Clear the instance filters.

    # File lib/sequel/plugins/instance_filters.rb
124 def clear_instance_filters
125   instance_filters.clear
126 end
initialize_copy(other) click to toggle source

Duplicate internal structures when duplicating model instance.

Calls superclass method
    # 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
instance_filters() click to toggle source

Lazily initialize the instance filter array.

    # File lib/sequel/plugins/instance_filters.rb
111 def instance_filters
112   @instance_filters ||= []
113 end
use_prepared_statements_for?(type) click to toggle source

Only use prepared statements for update and delete queries if there are no instance filters.

Calls superclass method
    # 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