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, line 53
def after_destroy
  super
  clear_instance_filters
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, line 59
def after_update
  super
  clear_instance_filters
end
freeze() click to toggle source

Freeze the instance filters when freezing the object

Calls superclass method
# File lib/sequel/plugins/instance_filters.rb, line 65
def freeze
  instance_filters.freeze
  super
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, line 73
def instance_filter(*args, &block)
  instance_filters << [args, block]
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, line 112
def _delete_dataset
  apply_instance_filters(super)
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, line 81
def _delete_without_checking
  if @instance_filters && !@instance_filters.empty?
    _delete_dataset.delete 
  else
    super
  end
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, line 117
def _update_dataset
  apply_instance_filters(super)
end
apply_instance_filters(ds) click to toggle source

Apply the instance filters to the given dataset

# File lib/sequel/plugins/instance_filters.rb, line 102
def apply_instance_filters(ds)
  instance_filters.inject(ds){|ds1, i| ds1.where(*i[0], &i[1])}
end
clear_instance_filters() click to toggle source

Clear the instance filters.

# File lib/sequel/plugins/instance_filters.rb, line 107
def clear_instance_filters
  instance_filters.clear
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, line 90
def initialize_copy(other)
  super
  @instance_filters = other.send(:instance_filters).dup
  self
end
instance_filters() click to toggle source

Lazily initialize the instance filter array.

# File lib/sequel/plugins/instance_filters.rb, line 97
def instance_filters
  @instance_filters ||= []
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, line 123
def use_prepared_statements_for?(type)
  if (type == :update || type == :delete) && !instance_filters.empty?
    false
  else
    super if defined?(super)
  end
end