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

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
121 def _delete_dataset
122   apply_instance_filters(super)
123 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
87 def _delete_without_checking
88   if @instance_filters && !@instance_filters.empty?
89     _delete_dataset.delete 
90   else
91     super
92   end
93 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
126 def _update_dataset
127   apply_instance_filters(super)
128 end
apply_instance_filters(ds) click to toggle source

Apply the instance filters to the given dataset

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

Clear the instance filters.

    # File lib/sequel/plugins/instance_filters.rb
116 def clear_instance_filters
117   instance_filters.clear
118 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
 96 def initialize_copy(other)
 97   super
 98   @instance_filters = other.send(:instance_filters).dup
 99   self
100 end
instance_filters() click to toggle source

Lazily initialize the instance filter array.

    # File lib/sequel/plugins/instance_filters.rb
103 def instance_filters
104   @instance_filters ||= []
105 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
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