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
55 def after_destroy
56   super
57   clear_instance_filters
58 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
61 def after_update
62   super
63   clear_instance_filters
64 end
freeze() click to toggle source

Freeze the instance filters when freezing the object

Calls superclass method
   # File lib/sequel/plugins/instance_filters.rb
67 def freeze
68   instance_filters.freeze
69   super
70 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
75 def instance_filter(*args, &block)
76   instance_filters << [args, block]
77 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
114 def _delete_dataset
115   apply_instance_filters(super)
116 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
83 def _delete_without_checking
84   if @instance_filters && !@instance_filters.empty?
85     _delete_dataset.delete 
86   else
87     super
88   end
89 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
119 def _update_dataset
120   apply_instance_filters(super)
121 end
apply_instance_filters(ds) click to toggle source

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

Clear the instance filters.

    # File lib/sequel/plugins/instance_filters.rb
109 def clear_instance_filters
110   instance_filters.clear
111 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
92 def initialize_copy(other)
93   super
94   @instance_filters = other.send(:instance_filters).dup
95   self
96 end
instance_filters() click to toggle source

Lazily initialize the instance filter array.

    # File lib/sequel/plugins/instance_filters.rb
 99 def instance_filters
100   @instance_filters ||= []
101 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
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